触发Jenkins建立在新标签和新标签之上。提交 [英] Triggering Jenkins build on both new tags & commits

查看:314
本文介绍了触发Jenkins建立在新标签和新标签之上。提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Git插件: https://wiki.jenkins- ci.org/display/JENKINS/Git+Plugin



目前,通过webhooks,只要将更改推送到GitHub,我们就会启动Jenkins构建。现在,我们希望在添加新标签时触发相同的构建。所以我们有两个触发条件:
$ b $ ol
代码更改被推送到GitHub

  • 标签是创建

  • 如果我们在此线程中尝试修复提及,那么构建仅针对标记开始。 如果发布新标签,jenkins会触发构建



    我们如何在两种情况下都做到这一点?



    问题#02:我们如何在Jenkins版本中获取标签名称,是否有任何环境变量。

    解决方案

    4步骤过程:


    1. 提交代码: git commit -m一些有意义的消息

    2. 创建标签


      • 发布到阶段: git tag -a release_stage_<有意义的标签>

      • 发布到产品: git tag -a release_production_<有意义的标签>

      >

    3. 推送标签推送标签: git push origin release_stage_< same_meaningful_tag>

    4. 提交
      git push origin< branch_name>

    Jenk ('Checkout Project')
    properties([pipelineTriggers([[$ class:''))


    $ b $ stage GitHubPushTrigger']])])
    checkout scm
    git_branch = env.BRANCH_NAME
    git_branch_to_release = env.BRANCH_NAME
    git_tag = sh returnStdout:true,script:'git tag -l - 点在HEAD'



    //现在您可以使用
    $ p
    $ b $ $ p $ if(currentBuild.result =='SUCCESSFUL'|| currentBuild.result =='SUCCESS'|| currentBuild.result == null)
    {
    if(git_tag.contains('release_stage')|| git_tag.contains('release_production'))
    {
    //执行任何操作你想用标签
    }
    }

    ```


    We are using the Git Plugin : https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

    Currently, via webhooks we start a Jenkins build whenever a change is pushed to GitHub. Now we want to trigger the same build when a new tag is added. So we have two triggering conditions :

    1. A code change is pushed to GitHub
    2. A tag is created

    If we try the fix mention in this thread then the builds start only for tags. jenkins trigger build if new tag is released

    How can we do it for both scenarios ?

    Question # 02 : How can we get the tag name inside a Jenkins build, is there any environment variable for it.

    解决方案

    4 Step Process:

    1. Commit Code : git commit -m "Some meaningful message"
    2. Create a tag
      • To release to stage : git tag -a release_stage_<meaningful tag>
      • To release to prod : git tag -a release_production_<meaningful tag>
    3. Push Tag Push the tag : git push origin release_stage_<same_meaningful_tag>
    4. Push Commit git push origin <branch_name>

    Jenkins File:

    stage('Checkout Project') properties([pipelineTriggers([[$class: 'GitHubPushTrigger']])]) checkout scm git_branch = env.BRANCH_NAME git_branch_to_release = env.BRANCH_NAME git_tag = sh returnStdout: true, script: 'git tag -l --points-at HEAD'

    //And now you can use to do anything with tags

    ```

    if(currentBuild.result=='SUCCESSFUL' || currentBuild.result=='SUCCESS' || currentBuild.result == null)
            {
                if (git_tag.contains('release_stage') || git_tag.contains('release_production'))
                {
                // Do anything which you want to do with tags
                }
    }
    

    ```

    这篇关于触发Jenkins建立在新标签和新标签之上。提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆