jenkins-pipeline - 如何在詹金斯的单个管道作业中触发多次运行?
问题描述
我有一个管道作业,它使用下面的管道 groovy 脚本运行,
pipeline {
parameters{
string(name: 'Unique_Number', defaultValue: '', description: 'Enter Unique Number')
}
stages {
stage('Build') {
agent { node { label 'Build' } }
steps {
script {
sh build.sh
}
}
stage('Deploy') {
agent { node { label 'Deploy' } }
steps {
script {
sh deploy.sh
}
}
stage('Test') {
agent { node { label 'Test' } }
steps {
script {
sh test.sh
}
}
}
}
我只是使用不同的唯一 ID 号作为输入参数多次触发此作业。因此,我将在不同阶段为这项工作进行多次运行/构建。
有了这个,我需要在这个管道作业中触发多次运行/构建以提升到下一个阶段(即,从构建到部署或从部署到测试)作为一个单一构建,而不是触发每个单独的运行/构建到下一阶段。有没有可能?
解决方案
我也试图做同样的事情,但没有找到相关的答案。愿这对某人有所帮助。
这将读取一个包含 Jenkins 作业名称的文件,并从一个作业中迭代地运行它们。
请在您的 Jenkins 中相应地更改以下代码。
pipeline {
agent any
stages {
stage('Hello') {
steps {
script{
git branch: 'Your Branch name', credentialsId: 'Your crendiatails', url: ' Your BitBucket Repo URL '
##To read file from workspace which will contain the Jenkins Job Name ###
def filePath = readFile "${WORKSPACE}/ Your File Location"
##To read file line by line ###
def lines = filePath.readLines()
##To iterate and run Jenkins Jobs one by one ####
for (line in lines) {
build(job: "$line/branchName",
parameters:
[string(name: 'vertical', value: "${params.vertical}"),
string(name: 'environment', value: "${params.environment}"),
string(name: 'branch', value: "${params.aerdevops_branch}"),
string(name: 'project', value: "${params.host_project}")
]
)
}
}
}
}
}
}
推荐阅读
- java - 如何确定 HttpClient PostMethod 的参数中包含 UTF-8 字符串?
- spring-boot - 集成数百种 SOAP 服务 - Spring Boot
- android - Android SDK 28 Android 9 和一些 ipad 上的 Phonegap App Json XMLHttpRequest() ProgressEvent 错误
- asp.net-mvc - FluentValidation 属性条件
- python - 更改默认的 seaborn 热图
- asp.net - 在 asp.net 中使用内容安全策略
- javascript - 无法使用 chrome 下的 javascript 控制表格的可见性
- sql - 使用递归 CTE 在 SQL OpenQuery 中发送参数
- asp.net-mvc - 如何使用 Bearer 令牌在我的网站中授权我的 web api 控制器?
- batch-file - 批量查找、清理和输出