Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • hello-world-template hello-world-template
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 9
    • Issues 9
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • ci-cd-discovery
  • templates
  • hello-world-templatehello-world-template
  • Issues
  • #6

Closed
Open
Created Nov 30, 2020 by Philippe Charrière@pcharriereOwner0 of 13 tasks completed0/13 tasks

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 keyword image to use a docker image
  • 2️⃣ you can create a variable with a multiline string with the pipe notation
  • 3️⃣ you can evaluate a JavaScript code in a string with NodeJS with the flag e: 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 to polyglot
  • use the python:slim image
  • HELLO_MESSAGE value is Hello 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 of HELLO_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

Edited Dec 01, 2020 by Philippe Charrière
Assignee
Assign to
Time tracking