在管道中,g_VersionNum定义了以下方法:
sshPublisher(publishers: [sshPublisherDesc(configName: 'VersionServer', transfers: [sshTransfer(excludes: '', execCommand: 'pwd;echo $${g_VersionNum}', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'alpha/${g_VersionNum}', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/abc-${g_VersionNum}.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
$ {g_VersionNum}在运行时空白。
当我使用20180327而不是$ {g_VersionNum}时:
sshPublisher(publishers: [sshPublisherDesc(configName: 'VersionServer', transfers: [sshTransfer(excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'f_alpha/20180327', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/abc-20180327.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
该脚本运行正常。
我试过逃生:\ $ {g_VersionNum},$$ {g_VersionNum},他们仍然无法工作。
我已经按照相同的步骤确认了参数定义:
sh 'echo ${g_VersionNum}'
可以正确显示该值 我已经测试过使用JENKINS环境变量,它们是有效的,只是我在管道中定义无效:
environment {
g_VersionNum = VersionNumber(versionNumberString: '${BUILD_YEAR}${BUILD_MONTH,XX}${BUILD_DAY,XX}', skipFailedBuilds: true, worstResultForIncrement: 'SUCCESS')
}
谁知道如何在sshPublisher插件中使用该参数?非常感谢!
答案 0 :(得分:1)
你必须改变'with',否则groovy将不会执行并获得g_VersionNum的值
答案 1 :(得分:0)
您应该使用“”而不是“”, 我使用''进行了测试,但没有效果:
sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '$DEPLOY_COMMAND', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '$SUB_MODULE/target', sourceFiles: '$SUB_MODULE/target/*.jar')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
但是使用“”可以起作用:
sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "$DEPLOY_COMMAND", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: "$SUB_MODULE/target", sourceFiles: "$SUB_MODULE/target/*.jar")], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])