docker - 如何使用 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 文件?
解决方案
所以经过一番研究,我tags
在 gitlab 中遇到了这个关键字。这使您可以为 1 个 yml 文件运行 2 个运行器。通过这种方式,我可以为我的构建、测试和 sonarqube fase 使用一个 shell 运行程序,为我的部署程序使用一个 docker 运行程序!
推荐阅读
- java - 在 Spring 控制器 REST 方法上未触发方法级别自定义约束
- python - 使用 python / ctypes 调用 GetThreadContext winapi
- swift - 分配 MyScuct().var = 结果导致没有分配
- python - 如何将列表中的随机值分配给同一行的另一列中不存在的新列?
- javascript - Javascript:切换自动向上或向下滚动
- gtk - 导入 Gtk 时脚本失败
- sql - Azure SQL 可以使用签名的存储过程吗
- polymer - 聚合物的发光元素是否可以使用 renderProps 模式?
- sql - 如何获取 URL 最后一部分中破折号之间的最后 3 个值
- vue.js - 生产和暂存构建不同