对于一个项目,我们希望调用一个 API 并将此curl 的结果保存在一个变量中。
管道是这样构建的:
stages:
- download
scan:
stage: download
image: ubuntu
variables:
TOKEN:
script:
- apk add curl
- apk add jq
- TOKEN=$('curl -H "Content-Type: application/json" -d "{\"username\":\"$USER", \"password\":\"$PWD"}" https://example.org/api2/authenticate | jq .token ')
#- echo $TOKEN
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
此 GitLab CI 配置无效:jobs:scan:script 配置应该是字符串或最多 10 层深度的嵌套字符串数组。
curl 命令(从 $() 中删除,但保留单引号来包裹双引号)正常工作并返回带有令牌的字符串。唯一的问题是将结果封装在变量中。可以做什么?
谢谢。
是否可以在一项作业中使用多个标签,如 Gitlab 文档的示例
工作:
标签:
- runnerA
- runnerB
对我来说,该配置最终会出现错误“此作业被卡住,因为您没有任何在线活跃跑步者,也没有分配给他们的任何这些标签”。
我们只使用共享跑步者,我可以找到分配给跑步者的标签
我尝试归档的是一项作业触发两个运行程序,并且运行程序在不同的服务器上工作。
问候
如果有人能帮助我解决以下问题,我将非常高兴。我想仅针对以给定标签名称开头的标签运行特定脚本。
以下规则适用于标签“wind-index”,但我需要的是正则表达式,因为我希望它也适用于“wind-index_0.1”等标签
rules:
- if: $CI_COMMIT_TAG == "wind-index"
when: always
Run Code Online (Sandbox Code Playgroud)
我期待这会起作用,但没有成功......
rules:
- if: $CI_COMMIT_TAG == \^wind-index\
when: always
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有可能的简单引号、双引号或 的组合\^wind-index.*\,但没有一个有效。
任何建议、帮助都非常受欢迎:-)
我有以下内容
\nstages:\n - stage1\n - stage2\nvariables:\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 MY_ENV_VAR:\xc2\xa0env_$CI_JOB_ID\nstage1_build:\n stage: stage1\n script:\n - echo $MY_ENV_VAR\nstage2_build:\n stage: stage2\n script:\n - echo $MY_ENV_VAR\nRun Code Online (Sandbox Code Playgroud)\n$MY_ENV_VAR我在两个阶段得到不同的值(这意味着$CI_JOB_ID每个阶段都有变化)。
我想要的是设置$MY_ENV_VAR一次 的一个值$CI_JOB_ID并将其设为常量,以便$MY_ENV_VAR在所有阶段使用相同的值。
代码:
include:
- project: 'testing-parent-pipeline/Testing-child-push'
file: 'script/test.yml'
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
testing-parent-pipeline/Testing-child-push未找到项目或访问被拒绝!确保管道配置中的所有包含内容均已正确定义。
在.gitlab-ci.yml中
stages:
- test-jq
test-jq:
stage: test-jq
image: ruby:2.5
script:
- apt-get update
- apt-get install -y git jq
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$GITLAB_USER_NAME"
- LAST_COMMIT_SHA=$(
curl -s \
--header "PRIVATE-TOKEN:$CLONE_KEY" \
"$CI_API_V4_URL/projects/$CI_PROJECT_ID/repository/commits/$CI_COMMIT_SHA" |\
jq -r '.parent_ids | del(.[] | select(. == "'$CI_COMMIT_BEFORE_SHA'")) | .[-1]'
)
Run Code Online (Sandbox Code Playgroud)
抛出错误:/bin/bash:第 158 行:jq:找不到命令
我在尝试使用 ChromeDriver 为网站运行单元测试时遇到问题。这是作业日志中的堆栈跟踪:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:37329/
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace: at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)
at ScamTeamWebsiteTests.Tests.Setup() in /builds/kostyabek/ScamTeamWebsiteTests/ScamTeamWebsiteTests/WebSiteTests.cs:line 19
Run Code Online (Sandbox Code Playgroud)
.yml …
以下是我设置自定义 Gitlab 运行程序所遵循的步骤:
按照此处的说明安装 Gitlab 运行程序:https ://docs.gitlab.com/runner/install/linux-repository.html
使用dockerexetuor 和docker:19image注册一个 runner
写gitlab-ci.yml如下:
image: docker:19.03.1
services:
- name: docker:19.03.1-dind
alias: docker
stages:
- build
build:
stage: build
variables:
IMAGE_TAG: repo.azurecr.io/some-repo
DOCKER_HOST: tcp://172.17.0.1:2375
DOCKER_TLS_CERTDIR: ''
script:
- docker login someacr.azurecr.io -u "$SERVICE_PRINCIPAL_USER" -p "$SERVICE_PRINCIPAL_PASSWORD"
- if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then docker build -t $IMAGE_TAG .; fi
Run Code Online (Sandbox Code Playgroud)
Login succeeded
if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then docker build -t $IMAGE_TAG .; fi
Cannot connect …Run Code Online (Sandbox Code Playgroud) 我想检查 gitlab-ci.yml 中的单个阶段中的分支是否是标签。然后根据分支是否是标签,执行一组特定的命令:
IF tag:
A SET OF COMMANDS
ELSE:
ANOTHER SET OF COMMAND
Run Code Online (Sandbox Code Playgroud)
我知道只有: -tags 可用于检查分支是否是标签,但是如何检查分支,然后在单个 gitlab-ci 阶段中根据分支类型应用不同的命令集?在这种情况下,如果分支不是标签,我将应用一组不同的命令。
some_stage:
only:
- tags
script:
- | SET OF COMMANDS
Run Code Online (Sandbox Code Playgroud) 我有一个 ci-cd 管道,当前正在使用以下除条件:
except:
- tags
- pushes
Run Code Online (Sandbox Code Playgroud)
随着条件的增加,现在我必须使用rules. 我现在无法使用onlyand exceptwith 规则。有人可以帮我弄这个吗?
我尝试过以下片段:
rules:
- if: 'tags && pushes'
when: never
Run Code Online (Sandbox Code Playgroud)
但这会产生以下错误:
jobs:build_info:rules:rule if invalid expression syntax
Run Code Online (Sandbox Code Playgroud)