【问题标题】:1 Jenkins Job with 2 Jenkinsfiles (declarative pipeline)1 个 Jenkins 作业和 2 个 Jenkinsfiles(声明性管道)
【发布时间】:2021-07-29 19:37:32
【问题描述】:

我有 1 个工作,有 2 个声明性管道脚本,我从 1 个脚本调用另一个脚本

现在我收到此错误消息:

java.lang.IllegalStateException: 只有一个管道 { ... } 块可以 一次执行。

stage('Loading app Deployment File') {
    steps {
        script {
           def util = load './abcd/Jenkinsfile.groovy'
        }
    }
}

【问题讨论】:

  • 我认为您确实想触发下游作业。
  • 没有 1 个作业我需要运行 2 个 Jenkins 文件

标签: groovy jenkins-pipeline jenkins-declarative-pipeline


【解决方案1】:

你不能在一个作业中使用两个管道脚本,我看到两个选项

  1. 创建另一个作业并将其称为下游作业

build job: "path/to/jenkins_job",parameters:([string(name:'', value:'')]), propagate: false, wait: true

  1. 从您的 jenkins 文件中将该文件作为闭包调用

    stage('foo'){
     options {
         timeout(time: 5, unit: "MINUTES")
     }
    
     steps{
         script{
             script1.call(arg1, arg2)
    
         }
     }
    

    }

并配置script1.groovy如下

script1.groovy

#!groovy

def call(arg1, arg2){
    try{
        <do something>
        return
    } catch (Exception){
        < something has failed >
    }

  // you can also add stages here

    stage('bar'){
      try{
          <do something>
          return
      } catch (Exception){
        < something has failed >
      } 
    }
}

需要注意的是,通过这种方法,所有管道变量都可以使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-27
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    相关资源
    最近更新 更多