GitLab管道未执行docker映像的脚本部分中的命令

时间:2020-09-09 16:32:01

标签: docker gitlab gitlab-ci

我正在尝试在.gitlab-ci.yml中运行以下作业/阶段

contract-tagging:
  image: pactfoundation/pact-cli:latest
  stage: contract-tag
  tags:
    - docker
  script:
    - broker create-version-tag --pacticipant service-name --version $CI_COMMIT_SHORT_SHA --tag production --broker-base-url http://localhost:9090

管道未在脚本部分中执行“代理”命令。但是,该阶段已成功完成。 我在日志中看到以下消息

Running before_script and script
00:01
 Could not find command "sh".
Running after_script
00:02
 Could not find command "sh".

下面是完整的日志。

Running with gitlab-runner 13.0.2 (772163a2)
   on csl-runner GwZBZUWZ
Preparing the "docker+machine" executor
00:08
 Using Docker executor with image pactfoundation/pact-cli:latest ...
 Pulling docker image pactfoundation/pact-cli:latest ...
 Using docker image sha256:d4188166dd9c3a1652ce9c63759f194f410322c6e9709df1c15efd07eba4297c for pactfoundation/pact-cli:latest ...
Preparing environment
00:02
 Running on runner-gwzbzuwz-project-7336-concurrent-0 via runner-gwzbzuwz-gitlab-nonprod-runner-agent-1599663074-8439e49e...
Getting source from Git repository
00:02
 $ git config --global http.sslVerify false; git config --global http.proxy http://proxy.local.xxxcloud.uk:yyyy; git config --global https.proxy http://proxy.local.xxxcloud.uk:yyyy;
 Fetching changes with git depth set to 50...
 Reinitialized existing Git repository in /builds/repo-name/.git/
 From https://gitlab.nonprod.xxxcloud.uk/repo-name
  * [new ref]         refs/pipelines/xxxx -> refs/pipelines/xxxx
 Checking out bb9d023e as cdc-pact-poc...
 warning: unable to rmdir 'bash-scripts': Directory not empty
 Removing .m2/repository/
 Removing bash-scripts/
 Removing target/
 Updating/initializing submodules...
Restoring cache
00:04
 Checking cache for default-1...
 No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
 Successfully extracted cache
Downloading artifacts
00:01
 Downloading artifacts for compile (3768666)...
 Downloading artifacts from coordinator... ok        id=3768666 responseStatus=200 OK token=Z3G8Ws6y
Running before_script and script
00:01
 Could not find command "sh".
Running after_script
00:02
 Could not find command "sh".
Saving cache
00:01
 Creating cache default-1...
 .m2/repository/: found 5176 matching files
 Archive is up to date!
 Created cache
Uploading artifacts for successful job
00:02
 Job succeeded

我在网上找不到任何解决方案。

请帮助。

1 个答案:

答案 0 :(得分:2)

您选择运行ci-stage的docker映像使用的入口点不允许运行带有CMD的脚本,正如Docker executor from gitlab所期望的那样。 您必须构建自己的映像,或者覆盖.gitlab-ci.yml

中的入口点
contract-tagging:
  image:
    name: pactfoundation/pact-cli:latest
    entrypoint: ["/bin/sh"]
相关问题