Home > OS >  Stop parallel Jenkins jobs from being superseded/skipped?
Stop parallel Jenkins jobs from being superseded/skipped?

Time:12-08

I am running a Jenkins job where I call another Jenkins job to build azure environments.

I create a 2d array [:] and store 3 jobs inside.

When I call the keyword 'parallel' on the array, the 3 jobs should run in parallel. This has worked for all my past Jenkins files, but when I run it here, it only runs one or two of the three jobs.

node(label: 'master')
{
    def branches = [:]

    stage ('Parallel Builds')
    {
        for (int i = 0; i < 3; i  ) 
        {
            branches["branch${i}"] = prepare(i)
        }
        
        echo "branches: ${branches}"
        parallel branches
    }

}

def prepare(def num)
{
    return {
            build job: 'Azure/Environment-General/Environment - Create', parameters: [
                                                                                [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snap-win10-19.6.9-boh-cfc-qs'],
                                                                                [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-' num]
                                                                                ]
    }
}

Jenkins console - skipping job when running in parallel

I am expecting all parallel jobs to run together but it keeps skipping one or two.

EDIT: I have also implemented a retry(3) for the failed branches but the jobs that fail just hang infinitely... below is the retry code as well as a picture to the jenkins console..

Jenkins console - jobs that fail hang

node(label: 'master')
{
    def branches = [:]
    branches.failFast = false

    stage ('Parallel Builds')
    {
        for (int i = 0; i < 3; i  ) 
        {
            branches["branch${i}"] = prepare(i)
        }
        
        echo "branches: ${branches}"
    }
    
    
    try 
    {    
        parallel branches
    }
    catch(Exception e) 
    {
        e.getCauses().each 
        {
            echo "${it.getShortDescription()}"
        }
    }

}

def prepare(def num)
{
    return {
        try
        {
            build job: 'Azure/Environment-General/Environment - Create', parameters: [
                                    [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snapPOSQSWithEDC1.2'],
                                    [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-0-PARALLEL-' num],
                                    [$class: 'StringParameterValue', name:'ResourceGroupName', value: 'rg-aloha-pos-automation']
                                    ]
            
        }
        catch(error) 
        {
            echo "First build failed, let's retry if accepted"
            retry(3) 
            {
                input "***Retry the job***"
                build job: 'Azure/Environment-General/Environment - Create', parameters: [
                                    [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snapPOSQSWithEDC1.2'],
                                    [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-PARALLEL-' num],
                                    [$class: 'StringParameterValue', name:'ResourceGroupName', value: 'rg-aloha-pos-automation']
                                    ]
            }  
        }
    }
}

CodePudding user response:

Try adding propagate: false to the build command.

build job: 'Azure/Environment-General/Environment - Create', propagate: false, parameters: [
                                                                                [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snap-win10-19.6.9-boh-cfc-qs'],
                                                                                [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-' num]

CodePudding user response:

Found a very stupid solution..... The job I was calling had the parameter checked off 'Do not allow concurrent builds'..... I unchecked and parallel works fine.

Will keep this up just in case anyone makes this mistake as well Lol

  • Related