在 gitlab-ci.yml 中运行多行脚本

时间:2021-07-28 16:26:16

标签: bash gitlab gitlab-ci

根据本文档,我尝试配置的管道遇到困难 - link

我正在尝试将示例管道代码集成到我当前的代码中,到目前为止:

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

但是,运行时我在输出中收到此错误:

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 "you@example.com"
  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

它似乎没有正确解析多行脚本,我无法弄清楚如何使其正常工作。我还在链接页面的原始脚本中看到,脚本的调用方式不同,老实说我不完全理解他们是如何调用脚本的。

任何帮助都会很棒。

0 个答案:

没有答案