【问题标题】:Equivalent block to environment in scripted pipeline with Jenkins与 Jenkins 脚本化管道中的环境等效块
【发布时间】:2019-07-25 11:32:10
【问题描述】:

我有以下管道:

    pipeline {
    agent any
    environment {
        branch = 'master'
        scmUrl = 'ssh://git@myrepo.git'
        serverPort = '22'
    }
    stages {
        stage('Stage 1') {
            steps {
                sh '/var/jenkins_home/contarpalabras.sh'
            }
        }
    }
}

我想将管道更改为“脚本化管道”,以便使用 try / catch 块并进行更好的错误管理。但是我没有在官方文档中找到等同于environment 的块。

【问题讨论】:

    标签: jenkins jenkins-pipeline block jobs environment


    【解决方案1】:

    你可以像这样使用 withEnv 块:

        node {
        withEnv(['DISABLE_AUTH=true',
                 'DB_ENGINE=sqlite']) {
            stage('Build') {
                sh 'printenv'
            }
        }
    }
    

    这个信息也在官方文档中:https://jenkins.io/doc/pipeline/tour/environment/#

    【讨论】:

    猜你喜欢
    • 2021-12-14
    • 2021-12-17
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多