[英]Use environment variable in parameter section of Jenkins pipeline
I have an environment variable which represents a gitrepo and I use this repo in my git parameter: 我有一个代表gitrepo的环境变量,我在git参数中使用了这个仓库:
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '1'))
disableConcurrentBuilds()
}
environment {
GitRepo = 'https://my-repo/repo.git'
}
parameters {
gitParameter branchFilter: 'origin/(.*support.*)', defaultValue: 'develop', name: 'SUPPORTBRANCH', type: 'PT_BRANCH', useRepository: env.GitRepo , sortMode: 'DESCENDING_SMART'
}
...}
When I use env.GitRepo inside the stages of my pipeline it works, but not when I use it in a parameter section. 当我在管道的各个阶段中使用env.GitRepo时,它可以工作,但是当我在参数部分中使用它时,它却无法工作。
How can I make this work? 我该如何进行这项工作?
Does it really need to be an environment variable? 是否真的需要一个环境变量? If not a simple property could do the trick.
如果不是一个简单的属性就可以解决问题。 Of course you can still use it to define the environment variable if required...
当然,如果需要,您仍然可以使用它来定义环境变量...
I used a string
parameter just because for me it seemed too difficult to get a simple example running using the gitParameter plugin. 我使用
string
参数只是因为对我来说,使用gitParameter插件运行一个简单的示例似乎太困难了。 But of course you can use the property also for the git parameter plugin. 但是,当然您也可以将该属性用于git参数插件。
// simply define the property here...
gitRepo = 'https://my-repo/repo.git'
pipeline {
agent any
environment {
// optional, not used below. Use only if you need to have an environment variable
GitRepo = gitRepo
}
options {
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '1'))
disableConcurrentBuilds()
}
parameters {
string defaultValue: gitRepo, description: '', name: 'Test', trim: false
}
stages {
stage ('foo') {
steps {
echo 'Hi'
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.