Gitlab pipeline error with source sh script

Viewed 40

I have a simple pipeline with one job to test bash scripts. The pipeline as follow:

image: alpine/git

stages:
  - test_branching

test_branch:
  stage: test_branching
  before_script:
    - mkdir -p .common
    - wget https://x.x.x.x/branching.sh > .common/test.sh && chmod +x .common/test.sh
    - source .common/test.sh
  script:
    - test_pipe
    - echo "app version is ${app_version}"

The bash script as follow:

#!/bin/sh

function test_pipe () {
    app_version="1.0.0.0-SNAPSHOT"
}

The problem is that the pipeline for whatever reason does not recognize the function inside the script. The logs are:

...
$ test_pipe
/scripts-1050-417479/step_script: eval: line 180: test_pipe: not found

Does anybody know what happend with this?? I miss a lot Jenkins shared libraries, gitlab does not have it, also gitlab does not have the function to include scripts inside yml files.

I dont want to use multiproject pipeline, I need to do it at this way. This is only an example of a more complicated pipeline logic.

Thanks in advance

1 Answers

As the documentation states before_script is just concatenated together with script and run on a single shell. The script you are downloading does not define test_pipe.

... gitlab does not have the function to include scripts inside yml files. It does, just use the YAML multiline literal syntax with |, e.g.:

  script:
    - |
      echo "this"
      echo "is"
      echo "an \
          example"
Related