如何在 Jenkins 声明式管道中设置 PATH [英] How to set PATH in Jenkins Declarative Pipeline
问题描述
在 Jenkins 脚本化管道中,您可以像这样设置 PATH 环境变量:
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,如此处所述https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-withenv-code-set-environment-variables :
要设置的环境变量列表,每个都在表单中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).
environment {
DISABLE_AUTH = 'true'
DB_ENGINE = 'sqlite'
}
理想情况下,我想更新 PATH 以在我的所有阶段使用自定义工具.
Ideally I would like to update the PATH to use custom tools for all my stages.
推荐答案
environment
部分是可能的:
pipeline {
agent { label 'docker' }
environment {
PATH = "/hot/new/bin:${env.PATH}"
}
stages {
stage ('build') {
steps {
echo "PATH is: ${env.PATH}"
}
}
}
}
有关信息,请参阅此答案.
这篇关于如何在 Jenkins 声明式管道中设置 PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!