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
  • #4

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

04-calc-functions

TODO

Part 1: make some calculations

  • create a merge request from this issue
  • open the WebIDE
  • update the .gitlab-ci.yml file
  • Deactivate the existing jobs by prefixing each job name by a .: hello becomes .hello
  • Create a new stage calculator
  • Create a new job addition belonging to calculator with:
    • 2 variables x and y
    • a script that adds x and y and displays the result
  • commit your changes, it will trigger the pipeline
  • observe the pipeline
  • observe the output of the pipeline
  • don't merge on master

Part 2: create a bash function

  • update the .gitlab-ci.yml file
  • write a bash function to use it in your CI script (🖐️ see the § Help, third point):
    • create a YAML anchor and add to it an add function that calculates the addition of 2 parameters $1 and $2
    • use it in your addition job, like this: add $x $y
  • 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 perform an arithmetic expression with bash, use this notation: $((expression))
  • To write a script in a multiline string (without the -at every line) you can use the |(pipe) notation:
    my-little-job:
      stage: my-stage
      tags: [docker]
      script: |
        echo "hello 1"
        echo "hello 2"
        echo "hello 3"
  • Use YAML anchors to define reusable functions:
    .tools: &tools |
      function hello() {
        echo "Hello $1" # $1 is the first argument of the function
      }
    
    my-little-job:
      stage: my-stage
      tags: [docker]
      before_script:
        - *tools
      script: |
        hello Bob # output: "Hello Bob"
Edited Dec 01, 2020 by Philippe Charrière
Assignee
Assign to
Time tracking