相关:如何在另一个jenkins管道B中调用jenkins管道A
我也想决定调用的工作空间和分支,否则 git 会出现问题,因为这项工作可能会同时被多次调用。如果我更改工作区,我希望它能够克隆/获取整个项目。这可能吗?
pipeline {
agent {...}
stages
{
stage('Start') {
steps {
sh 'ls'
}
}
stage ('Invoke_pipeline') {
steps {
---------------> Decide Workspace and Branch for this pipeline call, ideally see the steps in the ui too
build job: 'pipeline1', parameters: [
string(name: 'param1', value: "value1")
]
}
}
}
}
想要类似的东西
build job: 'pipeline1', workspace= /.A_Stage, branch= dev, parameters: [
string(name: 'param1', value: "value1")
你无法按照你尝试的方式去做。您必须在第二个管道中手动设置工作区。像下面这样。
管道A
pipeline {
agent any
stages {
stage('First Stage') {
steps {
script {
echo "Pipeline A"
build job: 'PipelineB', parameters: [string(name: 'WORKSPACE_PATH', value: 'some/path/to/new/workspace')]
}
}
}
}
}
管道B
pipeline {
agent any
parameters {
string(name: 'WORKSPACE_PATH', defaultValue: '', description: 'Path of the workspace from Pipeline A')
}
stages {
stage('Second Stage') {
steps {
script {
def workspacePath = params.WORKSPACE_PATH
echo "Received workspace path from Pipeline A: ${workspacePath}"
sh 'pwd'
// Changing the workspace
ws(workspacePath) {
echo "In new workspace"
sh 'pwd'
}
}
}
}
}
}