如何在Jenkins声明式管道中设置PATH [英] How to set PATH in Jenkins Declarative Pipeline
问题描述
在Jenkins脚本化管道中,您可以像这样设置PATH env变量:
In Jenkins scripted pipeline you can set PATH env variable like this :
node {
git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
withEnv(["PATH+MAVEN=${tool 'M3'}/bin"]) {
sh 'mvn -B verify'
}
}
请注意 PATH + MAVEN ,如此处
要设置的环境变量列表,每个形式为
VARIABLE = value或VARIABLE =取消设置否则定义的变量.你
也可以使用语法PATH + WHATEVER =/something前置/something
到$ PATH.
A list of environment variables to set, each in the form
VARIABLE=value or VARIABLE= to unset variables otherwise defined. You
may also use the syntax PATH+WHATEVER=/something to prepend /something
to $PATH. 但是我没有找到如何使用环境语法在声明式管道中执行此操作(如此处所述: https://jenkins.io/doc/pipeline/tour/environment ). But I didn't find how to do it in declarative pipeline using environment syntax (as explained here : https://jenkins.io/doc/pipeline/tour/environment). 理想情况下,我想更新PATH以在所有阶段使用自定义工具. Ideally I would like to update the PATH to use custom tools for all my stages. 在 有关信息,请参见此答案. 这篇关于如何在Jenkins声明式管道中设置PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
environment {
DISABLE_AUTH = 'true'
DB_ENGINE = 'sqlite'
}
推荐答案
environment
部分中可以:pipeline {
agent { label 'docker' }
environment {
PATH = "/hot/new/bin:$PATH"
}
stages {
stage ('build') {
steps {
echo "PATH is: $PATH"
}
}
}
}