首页 > 解决方案 > 如何使用 docker gitlab runner 运行 ./gradlew build?

问题描述

所以我试图让我的管道工作,但我一直卡住。

我的 git-ci.yml 文件有一个 docker 运行程序我这样做是因为我的部署阶段错误与 shell 运行程序(但我的构建、测试和 sonarqube 阶段确实与 shell 运行程序一起工作)

**git-ci.yml**

image: docker:latest
      
stages:
   - build
   - sonarqube-check
   - test
  - deploy

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

 build:
   stage: build
   image: gradle:jre11-slim
   script:
     - chmod +x gradlew
     - ./gradlew assemble
   artifacts:
     paths:
       - build/libs/*.jar
     expire_in: 1 week
   only:
     - master

 sonarqube-check:
   stage: test
   image: gradle:jre11-slim
   variables:
     SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
     GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
   cache:
     key: "${CI_JOB_NAME}"
     paths:
       - .sonar/cache
   script: ./gradlew sonarqube
   allow_failure: true
   only:
        - master

 test:
   stage: test
   script:
     - ./gradlew check



deploy:
  stage: deploy
  image: gradle:latest
  script:
  - apt-get update -qy
  - apt-get install -y ruby-dev
  - gem install dpl
  - dpl --provider=heroku --app=heroku-coalition --api-key=$HEROKU_API_KEY
  - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
  only:
  - master
    


after_script:
  - echo "End CI"

首先,我的 java home 出现错误,所以我切换了构建阶段的图像。现在我这样做了,并且不断收到有关权限的错误,所以我添加了 chmod +x gradlew

但是当我添加该行时出现此错误:

chmod:更改“gradlew”的权限:不允许操作

当我删除 chmod gradlew 行时,我得到:

/bin/bash:第 115 行:./gradlew:权限被拒绝

所以现在我真的不知道该怎么办。简而言之:我应该使用哪个运行器来让这个 yml 文件工作,或者我需要如何相应地编辑这个 yml 文件?

标签: dockergitlabyamlgitlab-cigitlab-ci-runner

解决方案


所以经过一番研究,我tags在 gitlab 中遇到了这个关键字。这使您可以为 1 个 yml 文件运行 2 个运行器。通过这种方式,我可以为我的构建、测试和 sonarqube fase 使用一个 shell 运行程序,为我的部署程序使用一个 docker 运行程序!


推荐阅读