我有一个时髦的脚本来并行进行一些测试,但我无法从 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()
}
}
}
}
未测试此代码。希望对:)有所帮助