我有一个groovy脚本并行测试,但我不能从jenkins UI手动重启Installation1 / Installation2阶段。有没有其他方法可以这样做,以便我可以重新启动特定的阶段?
pipeline {
agent {label ''}
stages {
stage('Check workspace') {
steps {
}
}
stage('Installation') {
parallel{
stage('Installation 1')
{
agent {label ''}
steps {
}
}
}
stage('Installation 2')
{
agent {label ''}
steps {
}
}
}
}
}
stage('Test') {
parallel{
stage(' Tests 1'){
agent {label ''}
steps {
}
}
stage(' Tests 2'){
agent {label ''}
steps {
}
}
}
}
stage('Report') {
steps {
}
}
}
}
您可以将installation1和installation2阶段定义为Jenkinsfile中的函数,并在测试失败时调用它们。这些功能可用于安装阶段以及测试失败时的重新安装。
def installation1() {
stage('Installation 1')
{
agent {label ''}
steps {
}
}
}
def installation2() {
stage('Installation 2')
{
agent {label ''}
steps {
}
}
}
在并行步骤中,您可以调用以下函数。测试失败时,使用try-catch调用安装函数。
stage('Test') {
try {
"TEST YOUR INSTALLATION"
} catch(error) {
echo "First test failed, let's retry installation if accepted"
retry(2) {
input "Retry the installation ?"
parallel{
installation1(),
installation2()
}
}
}
}
此代码未经过测试。希望能帮助到你 :)