Jenkins publish over cifs插件中提取SVN_TAG参数数字部分的实现方法问询
解决方法
你当前的配置存在两个核心问题导致无法提取SVN_TAG的数字部分:
environment块中定义TAG变量时使用了单引号,Groovy语法中单引号包裹的字符串不会执行内部的表达式计算,仅会将内容作为纯文本处理cifsPublisher的remoteDirectory配置中仍然引用原始的SVN_TAG参数,没有使用处理后的变量
具体修改操作
- 修正环境变量定义:将
TAG的赋值语句改用双引号包裹,同时添加兼容逻辑,避免当SVN_TAG为默认值trunk(不包含-字符)时抛出索引异常 - 调整发布路径配置:将
cifsPublisher中remoteDirectory的引用参数改为处理后的TAG变量,同时路径字符串改用双引号保证变量正常解析
修改后的完整代码
// Jenkins Declarative Pipeline def PRODUCT_VERSION pipeline { agent { label 'Windows Server 16 Node' } options { buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10')) } environment { // 新增兼容逻辑,识别不到-时直接返回原值 TAG = "${SVN_TAG.contains('-') ? SVN_TAG.substring(SVN_TAG.indexOf('-')+1) : SVN_TAG}" } 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: '[, ]+', // 路径改用双引号,引用处理后的TAG变量 remoteDirectory: "builds\\$JOB_BASE_NAME\\${TAG}", remoteDirectorySDF: false, removePrefix: '\\unsigned', sourceFiles: '\\unsigned\\*.exe']], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true]]) }
内容的提问来源于stack exchange,提问作者Ming
相关产品推荐
相关产品推荐

