gpt4 book ai didi

Jenkins 管道 : when condition and mercurial tags

转载 作者:行者123 更新时间:2023-12-05 03:55:43 25 4
gpt4 key购买 nike

仅当当前修订已使用版本号标记时,我才尝试运行我的 jenkins 构建(部署)的最后一步。我试图跟随 following example但它仅适用于 GIT。

这是我的设置:

  1. Jenkins 轮询我的存储库并从中提取 jenkinsfile
  2. 下面的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\""
    }
    }

不幸的是,部署部分每次都被忽略了...

构建截图:

Screenshot of the build

问题似乎如下:

  • Mercurial 标签确实是在 .hgtags 文件中添加了一行的提交

  • 当我拉取将被标记的修订时,它没有部署,因为还没有标记

  • 当我使用“标签提交”拉取修订版时,它没有被部署,标签引用了一个较旧的修订版。

你知道怎么做吗?

最佳答案

抱歉打扰了各位,我已经弄明白了。

我已经添加了:

  • 确定提交是否为 mercurial 标记的步骤。
  • 更新标签修订的步骤,如果标签以“release”开头
  • 变量 ${hgTagVersion} 可用于任何需要它的脚本。

来源如下:

// 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
}
}
}

这里是不需要部署时从blueocean看到的pipeline: enter image description here

当需要部署时: enter image description here

关于 Jenkins 管道 : when condition and mercurial tags,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59986005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com