简体   繁体   中英

Jenkins Gitlab multi-branch concurrent builds

Anyone has idea how to limit number of concurrent builds on Jenkins for multi-branch pipeline? I was searching out but almost every approach was about putting properties([disableConcurrentBuilds()]) which doesn't work in my case.

We use resource lock for unit tests, so they don't overlap. In my case no matter how many build executors I have they will just wait on lock to be released so they continue one by one while reserving build slot instead waiting in queue. I found some similar post:

Jenkins limit multibranch

for gitlab pipelines use parameter resource_group for create a resource group that ensures a job is mutually exclusive across different pipelines for the same project: https://docs.gitlab.com/ee/ci/yaml/#resource_group

for jenkins: plugin and parameter "Block build if certain jobs are running" https://plugins.jenkins.io/build-blocker-plugin/

Anyone with suggestion? So let me put additional info. We are using Gitlab multi branch pipeline. Property strategy is: "All branches get the same properties". Here is part of Jenkins file used:

pipeline {
    options { disableConcurrentBuilds() }
    agent any
    stages {
        stage('Prep Workspace') {
            steps {
                sh 'cp ...'
                sh 'cp ...'
                sh 'cp ...'
                sh 'cp ...'
                sh 'cp ...'
                sh 'composer install;'
            }
        }

        stage('Run Tests') {
            steps {
                // to avoid Fixture database overlap
                lock("unit_test_lock") {
                    sh ' test app AllTests --stderr --log-junit junit.xml'
                    junit 'junit.xml'
                }
            }
        }
    
    }

Lets say we have ten build executor. While one job from this branch is active, all others (coming from that multibranch) are filling the build executor slots and waiting for the first job to finish with message:

[unit_test_lock] is locked by Project-GitLab » stage #1049, waiting...

How to push these same jobs to queue instead of taking the build executor? I want other jobs that are not part of Gitlab multibranch to be able to build quickly without unnecessary waiting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM