Rob Wilkinson
Rob Wilkinson

Reputation: 1307

The GitLab pipeline is not executing the command in the script section for a docker image

I am trying to run the below job/stage in .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

The pipeline is not executing the 'broker' command in the script section. However the stage is completing with successful status. I see the below message in the log

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

Below is the complete log.

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

I could not find any solution on the web.

Please help.

Upvotes: 0

Views: 2564

Answers (1)

urfin78
urfin78

Reputation: 541

The docker image you choose to run your ci-stage uses an entrypoint that doesn't allow to run scripts with CMD, as is expected for the Docker executor from gitlab. You have to build your own image or you override the entrypoint in the .gitlab-ci.yml

contract-tagging:
  image:
    name: pactfoundation/pact-cli:latest
    entrypoint: ["/bin/sh"]

Upvotes: 2

Related Questions