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 tocalculator
with:- 2 variables
x
andy
- a script that adds
x
andy
and displays the result
- 2 variables
-
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
- create a YAML anchor and add to it an
-
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"