06-use-docker-images
It's possible to use a specific Docker image for the whole pipeline or for a specific job.
For example, I would like to display a message from my CI script using NodeJS, I will write something like that:
hello_javascript:
image: node:slim # 1️⃣
stage: polyglot
tags: [docker]
variables:
HELLO_MESSAGE: "Hello from JavaScript"
SOURCE_CODE: | # 2️⃣
message = process.env.HELLO_MESSAGE
console.log(message)
script:
- node -e "$SOURCE_CODE" # 3️⃣ 4️⃣
1️⃣ use the keywordimage
to use a docker image2️⃣ you can create a variable with a multiline string with the pipe notation3️⃣ you can evaluate a JavaScript code in a string with NodeJS with the flage
: node -e "console.log('👋 hello')"4️⃣ don't forget to surround the variable with"
to avoid interpolation issues
TODO:
Do the same thing as above, but with Python
-
create a merge request from this issue -
open the WebIDE -
update the .gitlab-ci.yml
file -
add a new stage: polyglot
-
add a new job: hello_python
belonging topolyglot
-
use the python:slim
image -
HELLO_MESSAGE
value isHello from Python
-
SOURCE_CODE
contains your Python source code -
add a script that runs python to execute the content of SOURCE_CODE
(and then to display the value ofHELLO_MESSAGE
) -
commit your changes, it will trigger the pipeline -
observe the pipeline -
observe the output of the pipeline -
merge on master (the pipe will be triggered again)
Help
- To evaluate a string with Python code from the command line, use the flag
c
:python -c "print('hello')"
- To get the value of an environment variable, use this method:
os.environ.get(variable_name)
-
you need to import
os
package before
-