仅当当前修订版本已被版本号标记时,我才尝试运行jenkins构建的最后一步(部署)。我尝试遵循following example,但仅适用于GIT。
这是我设置的内容:
将执行以下jenkinsfile
// --- Get sources from mercurial ---
stage ('Checkout') {
steps {
bat "Hg purge --config extensions.purge= --all --print"
checkout([$class: 'MercurialSCM', credentialsId: '', revision: 'default', source: 'MY_REPO'])
}
}
// --- BUILD ---
stage ('Build') {
// my build
}
// --- DEPLOY MASTER ---
stage ('Deploy') {
when { tag "release*" }
steps {
bat "\"${env.WORKSPACE}\\jenkins\\deploy.bat\" \"M:\\dev-FU4\""
}
}
不幸的是,每次都会忽略部署部分...
构建的屏幕截图:
问题似乎是以下问题:
Mercurial标签确实是一个提交,在.hgtags文件中添加了一行
当我拉出将被标记的修订时,由于没有标记,它尚未部署
当我使用“标签提交”拉动修订时,它没有被部署,并且标签引用的是较早的修订。
您对如何执行此操作有任何想法吗?
对那些打扰的家伙们很抱歉,我知道了。
我添加了:
以下是来源:
// Pipeline stages
stages {
// --- Get sources from mercurial ---
stage ('Checkout') {
steps {
bat "Hg purge --config extensions.purge= --all --print"
checkout([$class: 'MercurialSCM', credentialsId: '', revision: 'default', source: 'MY_REPO'])
}
}
stage ('Deployment determination') {
steps {
// Determine if Deploy is needed
script {
HG_LATEST_DESC = bat (
script: '@echo off & hg log --template {desc} --limit 1',
returnStdout: true
).trim()
// dummy test of a tag commit
// HG_LATEST_DESC = "Added tag release-test for changeset 1dcf7a76d27c"
deployIsNeeded = false
hgTag = ""
hgChgSet = ""
hgTagVersion = ""
hgsplit = HG_LATEST_DESC.split("Added tag ")
if (hgsplit.length == 2)
{
hgsplit = hgsplit[1].split(" for changeset ")
if(hgsplit.length == 2)
{
hgTag = hgsplit[0]
hgChgSet = hgsplit[1]
if(hgTag.contains("release-"))
{
deployIsNeeded = true;
hgTagVersion = hgTag.split("release-")[1]
}
}
}
if (deployIsNeeded)
{
println "Deploy is needed. Hg will checkout to tag and master will be deployed."
println "HG tag: ${hgTag}"
println "HG changeset: ${hgChgSet}"
println "Deploy version: ${hgTagVersion}"
}
else
{
println "Deploy is not needed. Build will remain local."
}
}
}
}
// --- Checkout to deploy tag ---
stage ('Deploy tag checkout')
{
when { expression { return deployIsNeeded; } }
steps {
bat "hg update --clean --rev ${hgChgSet}"
}
}
// --- BUILD ---
stage ('Build') {
// my build steps
}
// --- DEPLOY MASTER ---
stage ('Deploy') {
when { expression { return deployIsNeeded; } }
steps {
// my deployment script
}
}
}