如何在 Jenkins 脚本管道中设置 PATH 环境?

时间:2021-01-10 02:05:47

标签: jenkins jenkins-pipeline

我在本地机器的 Jenkins 安装上运行它。我试过这个现在有用。 shell 命令失败,因为它在 /usr/local/bin

中找不到 terrarom 可执行文件
node {
    withEnv(["PATH = /usr/local/bin:$env.PATH"]) {
        // The pipeline will fail it can't find terraform
        stage("Check terraform") { 
            sh "terraform --version"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

the documentation 中,使用 =withEnv 周围没有空格。

你想要的是

node {
    withEnv(["PATH=/usr/local/bin:$env.PATH"]) {
        stage("Check terraform") { 
            sh "terraform --version"
        }
    }
}