在jenkins中从shell脚本设置环境变量

时间:2019-08-20 05:38:27

标签: jenkins environment-variables jenkins-pipeline sh

我正在尝试使用Jenkins自动进行构建。我的构建过程需要执行三个不同的shell scripts。第一个脚本设置 some environment variables,第二个和第三个脚本会使用。 我正在詹金斯(Jenkins)从事一项pipeline工作,其中每个脚本都被逐步执行。但是,我无法从第一个脚本到下一个脚本获取环境变量。

注意:正在设置一组变量。因此,我不认为使用简单变量即可。

请帮助

1 个答案:

答案 0 :(得分:0)

您可能会混淆declarative pipeline with scripted pipeline

Jenkinsfile(声明性管道)

pipeline {
agent any

environment {
    DISABLE_AUTH = 'true'
    DB_ENGINE    = 'sqlite'
}

stages {
    stage('Build') {
        steps {
            sh 'printenv'
        }
    }
  }
}

Jenkinsfile(脚本化管道)

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