【问题标题】:Invoking plugins in declarative Jenkins pipeline在声明式 Jenkins 管道中调用插件
【发布时间】:2018-10-11 14:59:34
【问题描述】:

尝试将以下语法从脚本化管道移植到声明性管道,但它不起作用。显然,我收到错误消息,该步骤不是声明性 Jenkinsfile 中的有效关键字。找不到任何文档来解决此问题。有什么帮助吗?

stage("publish to s3") {
step([
    $class: 'S3BucketPublisher',
    entries: [[
        sourceFile: 'mybinaryFile',
        bucket: 'GoBinaries',
        selectedRegion: 'eu-west-1',
        noUploadOnFailure: true,
        managedArtifacts: true,
        flatten: true,
        showDirectlyInBrowser: true,
        keepForever: true,
    ]],
    profileName: 'myprofile',
    dontWaitForConcurrentBuildCompletion: false, 
])

}

【问题讨论】:

    标签: jenkins-declarative-pipeline


    【解决方案1】:

    在声明性管道中,stage 应该有 steps

    stages{
      stage('someName'){
        steps {
          //s3bucketpublisher step
        }
      }
    }
    

    参考:Jenkins documentation

    stage 指令位于stages 部分,并且应该包含一个steps 部分、一个可选的agent 部分或其他特定于stage 的指令。

    【讨论】:

    • 这个问题,我得到 $class 的语法错误。例如,stages{ stage('someName){ steps { $class: "S3BucketPublisher" - 生成语法错误 } } }
    • 只是为了确认一下,我忘记了 someName 后面的引用。我纠正了它。现在可以试试吗?
    • 感谢您的帮助。我按照您上面的建议添加了带有步骤的脚本标签。那行得通。
    【解决方案2】:

    只要代码在script 块中,这应该可以工作。这是在声明式管道中运行脚本化管道代码的标准方式。

    stage("publish to s3") {
      steps {
        script {
          step([
            $class: 'S3BucketPublisher',
            entries: [[
              sourceFile: 'mybinaryFile',
              bucket: 'GoBinaries',
              selectedRegion: 'eu-west-1',
              noUploadOnFailure: true,
              managedArtifacts: true,
              flatten: true,
              showDirectlyInBrowser: true,
              keepForever: true,
            ]],
            profileName: 'myprofile',
            dontWaitForConcurrentBuildCompletion: false, 
          ])
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 2017-08-31
      相关资源
      最近更新 更多