Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run multi line script in gitlab-ci.yml

I am having difficulty with my pipeline I'm trying to configured, based off of this document - link

I am trying to integrate the example pipeline code into my current one, I have got this far:

default:
  image:
    name: hashicorp/terraform:light
    entrypoint:
      - /usr/bin/env
      - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

stages:
  - validate
  - yor


validate:
  stage: validate
  before_script:
    - rm -rf .terraform
    - terraform --version
    - terraform init
    - export AWS_DEFAULT_REGION=eu-west-1
  script:
    - terraform validate -json
  only:
    - merge_requests    

run-yor:
  stage: yor
  image: ruby:2.5
  script:
    - git checkout ${CI_COMMIT_SHA}
    - export YOR_VERSION=0.1.62
    - wget -q -O - https://github.com/bridgecrewio/yor/releases/download/${YOR_VERSION}/yor-${YOR_VERSION}-linux-amd64.tar.gz | tar -xvz -C /tmp
    - /tmp/yor tag -d .
  after_script:
    - |
      cd $CI_PROJECT_DIR
      git status
      lines=$(git status -s | wc -l)
      if [ $lines -gt 0 ];then
        echo "committing"
        git config --global user.name "$AUTO_COMMITTER_NAME"
        git config --global user.email "$AUTO_COMMITTER_EMAIL"
        echo ".yor_plugins" >> .gitignore
        git add .
        git commit -m "YOR: Auto add/update yor.io tags."
        git push -o ci.skip "https://${GITLAB_USER_NAME}:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}"
      else
        echo "no updated resources, nothing to commit."
      fi
  only:
    - merge_requests

However, when running I receive this error in the output:

Running after_script
00:01
Running after script...
$ cd $CI_PROJECT_DIR # collapsed multi-line command
HEAD detached at c839d93
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
    modified:   cloudformation.tf
no changes added to commit (use "git add" and/or "git commit -a")
committing
*** Please tell me who you are.
Run
  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <>) not allowed

It seems like it is not parsing the multi line script correctly and I cannot figure out how exactly to get this working. I also see in the original script on the linked page, the script is called differently, I'll be honest I don't fully understand how they are calling the script.

Any help would be great.

like image 743
fraserc182 Avatar asked Apr 27 '26 02:04

fraserc182


2 Answers

deploy:native-application:
  stage: deploy
  script:
    - |
      mvn $MAVEN_CLI_OPTS package -DskipTests \
      -Pnative \
      -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel:21.3.0.0-Final-java17 \
      -Dquarkus.container-image.push=true

https://docs.gitlab.com/ee/ci/yaml/script.html#split-long-commands

like image 137
agilob Avatar answered Apr 30 '26 11:04

agilob


The # collapsed multiline command can be prevented with

  variables:                                                                                                                                                   
    FF_SCRIPT_SECTIONS: "true"                                                                                                                                 

see:

  • GitLab Runner feature flags | GitLab and
  • Improve the collapsible element logic (!4487) · Merge requests · GitLab.org / gitlab-runner · GitLab and
  • Multi-line command output can be un-collapsed in Job terminal output view [BASH Shell] (#3392) · Issues · GitLab.org / gitlab-runner · GitLab
like image 25
jo-so Avatar answered Apr 30 '26 09:04

jo-so



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!