首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在gitlab-ci.yml中运行多行脚本

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

Stack Overflow用户
提问于 2021-07-28 16:26:16
回答 1查看 6.3K关注 0票数 4

基于本文档- 链接,我在尝试配置管道时遇到了困难。

我正在尝试将示例管道代码集成到我当前的代码中,我已经完成了以下工作:

代码语言:javascript
运行
复制
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

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

代码语言:javascript
运行
复制
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

它似乎没有正确地解析多行脚本,而且我也不知道如何准确地实现这个工作。我还在链接页面的原始脚本中看到,脚本的调用方式不同,老实说,我不完全理解他们是如何调用脚本的。

任何帮助都会很好。

EN

回答 1

Stack Overflow用户

发布于 2022-01-29 13:07:32

代码语言:javascript
运行
复制
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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68564107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档