Jenkins插件中参数的引用部分"publish over cifs"
Reference part of the parameter in Jenkins plugin "publish over cifs"
全部
下面是我的 jenkinsfile。我定义了一个参数“SVN_TAG”来列出 SVN 标签。 SVN标签的格式是“VERSION-Digit.Digit.Digit”。现在我只能在 cifsPublisher“RemoteDirectory”设置中引用整个参数。但我只想引用参数的数字部分(如“2.2.2”),我应该怎么做?谢谢。
// Jenkins Declarative Pipeline
def PRODUCT_VERSION
pipeline {
agent { label 'Windows Server 16 Node' }
options {
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
}
environment {
TAG = '${SVN_TAG.substring(SVN_TAG.indexOf(\'-\')+1)}'
}
stages {
stage('Initialize') {
steps {
script {
PRODUCT_VERSION = "3.2.0.1"
}
}
}
stage('Setup parameters') {
steps {
script {
properties([
parameters([
[ $class: 'ListSubversionTagsParameterDefinition',
credentialsId: 'xxxxxxxxxxx',
defaultValue: 'trunk', maxTags: '',
name: 'SVN_TAG',
reverseByDate: false,
reverseByName: true,
tagsDir: 'https://svn-pro.xxxx.net:xxxxxx',
tagsFilter: ''
],
])
])
}
}
}
stage('Build') {
steps {
cleanWs()
checkoutSource()
buildSource()
buildInstaller()
}
}
stage('Deploy') {
steps {
copyArtifacts()
}
}
}
}
def copyArtifacts() {
cifsPublisher(publishers: [[configName: 'Server', transfers: [[cleanRemote: false, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'builds\$JOB_BASE_NAME\${SVN_TAG}', remoteDirectorySDF: false, removePrefix: '\unsigned', sourceFiles: '\unsigned\*.exe']], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true]])
}
你的环境变量的想法是正确的方法,只需使用双引号(""
)而不是单引号(''
)来允许字符串插值,它是否只适用于双引号 groovy。您可以在 Groovy String Documentation.
中阅读更多内容
所以只需使用 TAG = "${SVN_TAG.split('-')[1]}"
.
然后在任何需要的地方使用该标签,您可以将其传递给相关函数,例如 copyArtifact
或按原样使用它:"builds\$JOB_BASE_NAME\${TAG}"
.
全部
下面是我的 jenkinsfile。我定义了一个参数“SVN_TAG”来列出 SVN 标签。 SVN标签的格式是“VERSION-Digit.Digit.Digit”。现在我只能在 cifsPublisher“RemoteDirectory”设置中引用整个参数。但我只想引用参数的数字部分(如“2.2.2”),我应该怎么做?谢谢。
// Jenkins Declarative Pipeline
def PRODUCT_VERSION
pipeline {
agent { label 'Windows Server 16 Node' }
options {
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
}
environment {
TAG = '${SVN_TAG.substring(SVN_TAG.indexOf(\'-\')+1)}'
}
stages {
stage('Initialize') {
steps {
script {
PRODUCT_VERSION = "3.2.0.1"
}
}
}
stage('Setup parameters') {
steps {
script {
properties([
parameters([
[ $class: 'ListSubversionTagsParameterDefinition',
credentialsId: 'xxxxxxxxxxx',
defaultValue: 'trunk', maxTags: '',
name: 'SVN_TAG',
reverseByDate: false,
reverseByName: true,
tagsDir: 'https://svn-pro.xxxx.net:xxxxxx',
tagsFilter: ''
],
])
])
}
}
}
stage('Build') {
steps {
cleanWs()
checkoutSource()
buildSource()
buildInstaller()
}
}
stage('Deploy') {
steps {
copyArtifacts()
}
}
}
}
def copyArtifacts() {
cifsPublisher(publishers: [[configName: 'Server', transfers: [[cleanRemote: false, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'builds\$JOB_BASE_NAME\${SVN_TAG}', remoteDirectorySDF: false, removePrefix: '\unsigned', sourceFiles: '\unsigned\*.exe']], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true]])
}
你的环境变量的想法是正确的方法,只需使用双引号(""
)而不是单引号(''
)来允许字符串插值,它是否只适用于双引号 groovy。您可以在 Groovy String Documentation.
所以只需使用 TAG = "${SVN_TAG.split('-')[1]}"
.
然后在任何需要的地方使用该标签,您可以将其传递给相关函数,例如 copyArtifact
或按原样使用它:"builds\$JOB_BASE_NAME\${TAG}"
.