詹金斯管道:当条件和水银标记时

问题描述 投票:1回答:1

仅当当前修订版本已被版本号标记时,我才尝试运行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文件中添加了一行

  • 当我拉出将被标记的修订时,由于没有标记,它尚未部署

  • 当我使用“标签提交”拉动修订时,它没有被部署,并且标签引用的是较早的修订。

您对如何执行此操作有任何想法吗?

jenkins tags mercurial
1个回答
0
投票

对那些打扰的家伙们很抱歉,我知道了。

我添加了:

  • 确定提交是否为水银标签的步骤。
  • 如果标签以“ 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查看的管道:enter image description here

并且需要部署时:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.