Jenkins

From miki
Revision as of 17:26, 25 January 2021 by Mip (talk | contribs) (Created page with "== Tips == === Cancel older builds if new one starting === Using <code>milestone</code>, we can cancel older builds if a new commit is pushed. Here an example where all new b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Tips

Cancel older builds if new one starting

Using milestone, we can cancel older builds if a new commit is pushed.

Here an example where all new build cancels the older ones, except on the master branch. This is useful to increase throughput of Jenkins slaves. This policy makes sense since non-master branches typically do not require thorough testing/analysis.

    stage('UTs')
    {
        // if not on master and older builds are ongoing, cancel them !
        if ( env.BRANCH_NAME != 'master' )
        {
            def buildNumber = env.BUILD_NUMBER as int
            if (buildNumber > 1) milestone(buildNumber - 1)
            milestone(buildNumber)
        }
        // ...
    }