【问题标题】:in this jenkins declarative pipeline, how can I pass a value to DIABLE_AUTH from a file?在这个 jenkins 声明性管道中,如何将值从文件传递给 DIABLE_AUTH?
【发布时间】:2017-04-21 07:23:53
【问题描述】:
pipeline {
    agent any

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

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

我尝试加载(/path/to/file),但它给了我一个错误(unexpected char '\')

【问题讨论】:

  • 我不知道你为什么想要,但这只是一个时髦的 DSL。您可以访问所需的任何凹槽 IO 操作。

标签: jenkins groovy environment-variables jenkins-pipeline


【解决方案1】:

只需使用可用的readFile 步骤即可。

这一步会将工作区中的文件解析为字符串。 然后您可以从此字符串中读取 DISABLE_AUTH 并在管道脚本中使用它。

这是一个示例脚本。

def content = readFile 'gradle.properties'

Properties properties = new Properties()
InputStream is = new ByteArrayInputStream(content.getBytes());
properties.load(is)

def runtimeString = 'DIABLE_AUTH'
echo properties."$runtimeString"
DIABLE_AUTH= properties."$runtimeString"
echo DIABLE_AUTH

【讨论】:

    猜你喜欢
    • 2018-01-24
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2021-01-01
    • 2022-08-05
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多