Search code examples
dockergitlab-cigitlab-ci-runner

GitLab CI jobs fail when docker executor is used but pass with shell executor


I have set up a GitLab CI with two runners - one of them uses docker executor, while the other one uses shell. The runner with shell executor works fine, however, the docker one fails every time after the ./gradlew.bat --stop step because of errors in gradlew.bat.

BUILD SUCCESSFUL in 25s
5 actionable tasks: 5 executed
$ ./gradlew.bat --stop
./gradlew.bat: line 1: @rem: command not found
./gradlew.bat: line 2: @rem: command not found
./gradlew.bat: line 3: @rem: command not found
./gradlew.bat: line 4: syntax error near unexpected token `('
./gradlew.bat: line 4: `@rem Licensed under the Apache License, Version 2.0 (the "License");'
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

YAML file:

build:
  stage: build
  script:
    - cd myproject/
    - ./gradlew build -x test
    - ./gradlew.bat --stop

test:
  stage: test
  script:
    - cd myproject/
    - ./gradlew test
    - ./gradlew.bat --stop

Solution

  • The issue turned out to be caused by me trying to execute a batch file (.bat) in a Linux docker container.

    I fixed the problem by changing - ./gradlew.bat --stop to - ./gradlew --stop in the YAML file.

    According to to the Gradle documentation the gradlew.bat and gradlew perform the same job where the .bat is intended for use with Windows.