【问题标题】:Jenkins Pipeline Jenkinsfile: 'node' and 'pipeline' directivesJenkins Pipeline Jenkinsfile: 'node' 和 'pipeline' 指令
【发布时间】:2017-11-23 06:47:57
【问题描述】:

我开始使用Jenkins declarative Pipeline。从我看到的一些示例中,我注意到 Jenkinsfile 是使用 Pipeline 指令设置的:

pipeline {
    agent any 

    stages {
        stage('Build') { 
            steps { 
                sh 'make' 
            }
        }
        stage('Test'){
            steps {
                sh 'make check'
                junit 'reports/**/*.xml' 
            }
        }
        stage('Deploy') {
            steps {
                sh 'make publish'
            }
        }
    }
}

在其他示例中,我注意到 Jenkinsfile 是使用节点指令设置的:

node {
    stage 'Checkout'
        checkout scm

    stage 'Build'
        bat 'nuget restore SolutionName.sln'
        bat "\"${tool 'MSBuild'}\" SolutionName.sln /p:Configuration=Release /p:Platform=\"Any CPU\" /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}"

    stage 'Archive'
        archive 'ProjectName/bin/Release/**'

}

我无法找到关于何时/为什么使用这些的可靠文档。有没有人知道为什么这些不同以及何时适合使用它们中的任何一个?

我不确定,但我相信 'node' 指令用于脚本化管道而不是声明性管道。

提前感谢您的任何指导。

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    是的,顶级 node 意味着脚本化管道,顶级 pipeline 意味着声明式管道。

    声明式似乎是更面向未来的选项,也是人们推荐的选项,例如在jenkins user list post 中,核心贡献者说“去声明式”。它是 Visual Pipeline Editor 唯一可以支持的。它支持验证。它最终具有脚本化的大部分功能,因为您可以在大多数情况下回退到脚本化。偶尔有人会提出一个用例,他们不能完全用声明式做他们想做的事情,但这通常是使用脚本化一段时间的人,这些功能差距可能会及时缩小。最后,如果您真的不得不选择其中一个,那么编写一个从声明式到脚本式的程序化翻译器会比其他方式更容易(根据定义,因为语法受到更严格的限制)。

    更多关于声明式优点的上下文来自一般可用性博客文章:https://jenkins.io/blog/2017/02/03/declarative-pipeline-ga/

    我能找到的最官方的文档都提到了(截至 2017 年 6 月 21 日):https://jenkins.io/doc/book/pipeline/syntax/

    【讨论】:

      猜你喜欢
      • 2016-08-21
      • 1970-01-01
      • 2017-07-12
      • 2019-12-21
      • 2016-10-18
      • 2016-10-07
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多