是否可以将gitlab ci作业标记为手动启动?
我需要它来部署应用程序,但我想决定它是否将被部署
continuous-deployment continuous-delivery gitlab gitlab-ci gitlab-ci-runner
我有一个像这样的GitLab CI构建脚本:
create release:
stage: deploy
tags:
- basic
only:
- tags
script:
- GITLOG=$(echo "# Changes Log"; git log `git tag | tail -2 | head -1`..${CI_BUILD_TAG} --pretty=format:" - %s")
- curl -X POST -d "private_token=$CI_BUILD_TOKEN&description=$GITLOG" "http://git.example.com/api/v3/projects/${CI_PROJECT_ID}/repository/tags/${CI_BUILD_TAG}/release"
Run Code Online (Sandbox Code Playgroud)
此步骤的目的是在GitLab发行版部分中自动从Git添加更改日志.
如果我在命令行上手动运行它并输入变量,那么这是有效的...
问题是CI_BUILD_TOKEN构建运行器中的值不是有效的GitLab专用令牌 - 它只是连接到Docker注册表的令牌 - 根据文档.
有没有办法获得一个有效的GitLab API令牌,构建运行器可以使用它来访问它正在运行构建的项目的API?似乎这应该是可能的.
GitLab Runner:
gitlab-runner -v
Version: 1.2.0
Git revision: 3a4fcd4
Git branch: HEAD
GO version: go1.6.2
Built: Sun, 22 May 2016 20:05:30 +0000
OS/Arch: linux/amd64
Run Code Online (Sandbox Code Playgroud) 假设我在中定义了这些阶段.gitlab-ci.yml:
stages:
- build
- analysis
- tests
- deploy
- post-deploy
Run Code Online (Sandbox Code Playgroud)
由于analysis需要花费很多时间并且我并不真正关心结果(我也已经allow_failure: true设置) - 是否可以以某种方式定义开始analysis然后立即启动下一阶段tests?
我在官方文档上没有找到任何类似主题的参考。
编辑:
主要思想是所有其他阶段都可以运行,就好像它们analysis根本不存在一样。如果我将 和 置于analysis同一阶段tests,那么 和analysis都会tests同时运行,但是deploy直到它们都完成后才会启动。这可不行。我想tests完成然后启动deploy,deploy完成后我想启动post-deploy。我真的不关心analysis结果,我只是想触发它并继续部署。
这是我的代码 giltlab-ci.yml :
before_script:
##
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
##
## Run ssh-agent (inside the build environment)
##
- eval $(ssh-agent -s)
##
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes …Run Code Online (Sandbox Code Playgroud) 我正在使用 otj-pg-embedded 对嵌入式 postgres 数据库运行一些测试。虽然测试在本地运行良好,但在 Gitlab-CI 运行时会失败,并出现非法状态异常。Gitlab CI 构建它并运行不包含 otj-pg-embedded 的测试就好了。
我已经注释掉了大部分测试类并将问题定位为:
public static SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance();
Run Code Online (Sandbox Code Playgroud)
import com.goldfinger.models.AuditLog;
import com.opentable.db.postgres.embedded.FlywayPreparer;
import com.opentable.db.postgres.junit.EmbeddedPostgresRules;
import com.opentable.db.postgres.junit.PreparedDbRule;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class SQLAuditRepositoryTest {
private static SQLAuditRepository sqlAuditRepository;
private static AuditLog auditLog_1;
private static AuditLog auditLog_2;
private static AuditLog auditLog_3;
private static List<AuditLog> auditLogList;
@ClassRule
public static SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance();
@Test
public void simpleTest() {
assert (2 == 2);
}
}
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
java.lang.IllegalStateException: Process …Run Code Online (Sandbox Code Playgroud) 我正在 Gitlab CI 中的 selenium 中设置用于自动化测试的 CI 作业,但由于该问题,测试失败。
019-09-27T11:03:17.404Z INFO @wdio/cli:Launcher:运行 onPrepare hook /builds/shauryav/test-react-ci-cd/node_modules/chromedriver/lib/chromedriver/chromedriver:加载共享库时出错: libnss3.so:无法打开共享对象文件:没有这样的文件或目录
我尝试了许多解决方案,例如安装包 "@wdio/cli": "^5.13.2", "webdriverio": "^5.13.2" 但没有任何效果。注意,我没有使用任何 docker 设置
/builds/shauryav/test-react-ci-cd/node_modules/chromedriver/lib/chromedriver/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
2019-09-27T11:03:27.415Z ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: timeout
at Timeout.timeoutFunc (/builds/shauryav/test-react-ci-cd/node_modules/tcp-port-used/index.js:204:25)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)```
Run Code Online (Sandbox Code Playgroud) 我知道您可以使用 yaml 锚点在 before 脚本中重用代码块:
.something_before: &something_before
- echo 'something before'
before_script:
- *something_before
- echo "Another script step"
Run Code Online (Sandbox Code Playgroud)
.yml但是当 .something_before通过.something_before 在共享文件中声明时,这似乎不起作用include:file。它似乎也不extends适用于before_script. 有谁知道如何重用before_script共享.yml文件中的某些步骤?
编辑:我的用例是我有 2 个 gitlab 项目,它们的 before_script 步骤几乎相同。我不想在发生更改时都必须更改这两个项目,因此我有第三个单独的 Gitlab 项目,其中包含一个 .yml 模板,我通过 include:file 将其包含在两个项目中。我想将所有通用代码放入该共享模板中,并且对于具有两个额外步骤的 git 项目,只有两行 before_script 。
我懂了
/bin/sh: eval: line 98: bash: not found
Run Code Online (Sandbox Code Playgroud)
通过执行 gitlabb .yml 文件来发送消息。
我在前面的脚本部分添加了这一行
- apk update && apk add openssh
Run Code Online (Sandbox Code Playgroud)
这没有帮助。
before_script:
- apk update && apk add openssh
- bash docker_install.sh > /dev/null
stages:
- build
- deploy
- loadtest-local
build:
stage: build
script:
- echo "building my application in ubuntu container..."
deploy:
stage: deploy
image: php:7.4
script:
- phpunit Unittest.php
loadtest-local:
image:
name: loadimpact/k6:latest
entrypoint: [""]
stage: loadtest-local
script:
- k6 run ./loadtests/performance-test.js
- k6 run ./loadtests/inttest.js
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我有一个预定的管道,每天一次将一些数据从一台服务器复制到另一台服务器。
管道在所有分支上都能正常工作,但如果我选择master分支(默认分支)作为target branch.
我已经尝试过一个精确的副本master,效果很好。
我认为这可能是因为master受保护,但我尝试了受保护的 master 副本,它起作用了。
我真的不确定发生了什么事。当我单击计划管道旁边的“播放”按钮时,它表示作业已成功计划,但我在作业列表中看不到任何作业。
这里有一些详细信息.gitlab-ci.yml
stages:
- copy_data
- linting
- test
- deploy
lint:
needs: []
stage: linting
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH'
changes:
- "my_project/**/*.py"
script:
- ...
test:
stage: test
script:
- ...
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH'
copy_database:on-schedule:
stage: …Run Code Online (Sandbox Code Playgroud) 我们正在与 GitLab CI 合作,刚刚发生了一个奇怪的行为。我们尝试仅在文件发生更改并且处于合并请求而不是简单的 git 分支时运行给定作业(例如,lint如下所示) 。*.py例如,如果我要在 上推送更改Readme.MD,则此处管道的作业Lint将在不应该执行的地方执行。
.gitlab-ci.yml配置:
image: python:3.7
stages:
- pre-build
- test
.ci_rules:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_IID'
changes:
- tests/*.py
- tests/*/*.py
- src/*.py
- src/*/*.py
- if: $CI_COMMIT_REF_NAME == "develop"
- if: $CI_COMMIT_REF_NAME == "main"
lint:
stage: pre-build
script:
- pip install flake8
- flake8
rules:
- !reference [ .ci_rules, rules ]
# [... other jobs not relevant for the issue]
Run Code Online (Sandbox Code Playgroud)