@Library('shared-lib') _ properties([ buildDiscarder(logRotator(artifactNumToKeepStr: '10', numToKeepStr: '10')), pipelineTriggers( [GenericTrigger( causeString: 'Generic Cause', allowSeveralTriggersPerBuild: false, genericVariables: [[key: 'jsonEvent', value: '$']], token: env.JOB_NAME) ] ) ]) Map projects = [ 'DevOps/jenkins-pipelines': [ [ 'branches': ['master'], 'jobs': [ [job: 'jobs-dsl/jobs-dsl'] ] ], ], 'DevOps/ansible': [ [ 'branches': ['master'], 'jobs': [ [job: 'Automation/DevOps/vault-policies-and-roles-update'] ] ], ] ] String getBranch(Map fullJSON) { String branch = '' String refHead = 'refs/heads/' String refTags = 'refs/tags/' if (fullJSON.ref != null && fullJSON.ref.contains(refHead)) { branch = fullJSON.ref.split(refHead).last() } else if (fullJSON.ref != null && fullJSON.ref.contains(refTags)) { branch = fullJSON.ref.split(refTags).last() } else if (fullJSON.ref != null) { branch = fullJSON.ref } return branch } podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"), yaml: getPodTemplate('alpine')) { node(POD_LABEL) { stage('Run job') { try { Map fullJSON = readJSON text: jsonEvent String projectName = fullJSON.repository.full_name currentBuild.description = "Repo: ${fullJSON.repository.full_name}" currentBuild.displayName = "#${env.BUILD_ID} Skip" //info for Debug //println(fullJSON) if (projects[projectName]) { String branch = getBranch(fullJSON) currentBuild.description = "Repo: ${fullJSON.repository.full_name} $branch" projects[projectName].each { Map project -> if (project.branches.contains(branch) || project.branches == []) { currentBuild.displayName = "#${env.BUILD_ID} Run on ${branch}" project.jobs.each { Map job -> build job: job.job, parameters: [ string(name: 'PROJECT_NAME', value: projectName), string(name: 'BRANCH_NAME', value: branch), string(name: 'DATA_JSON', value: fullJSON.toString()) ], wait: false } } } } // Start tasks for all repositories by PR if (fullJSON.action == 'opened') { currentBuild.displayName = "#${env.BUILD_ID} run on PR" build job: 'gitea-events/eva-pr-link-webhook', parameters: [ string(name: 'DATA_JSON', value: fullJSON.toString()) ], wait: false } } catch (groovy.lang.MissingPropertyException e) { println 'This job should run through gitea webhook:\n' + e } finally { cleanWs() } } } }