diff --git a/pipelines/gitea-events/jobs-runner.groovy b/pipelines/gitea-events/jobs-runner.groovy index 28c19c1..f96b357 100644 --- a/pipelines/gitea-events/jobs-runner.groovy +++ b/pipelines/gitea-events/jobs-runner.groovy @@ -24,7 +24,7 @@ Map projects = [ ], 'DevOps/ansible': [ [ - 'branches': [], + 'branches': ['master'], 'jobs': [ [job: 'Automation/DevOps/vault-policies-and-roles-update'] ] @@ -32,27 +32,23 @@ Map projects = [ ] ] -podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"), - yaml: """ - apiVersion: v1 - kind: Pod - spec: - containers: - - name: linux - image: ${env.JENKINS_DOCKER_REGISTRY}/docker-hub-proxy/library/alpine:3.18.5 - command: - - sleep - args: - - 99d - resources: - limits: - cpu: 100m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -""" -) { +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 { @@ -60,32 +56,25 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"), 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 (fullJSON.ref) { - String branch = '' - currentBuild.description = "Repo: ${fullJSON.repository.full_name} $branch" - String refHead = 'refs/heads/' - String refTags = 'refs/tags/' + if (projects[projectName]) { + String branch = getBranch(fullJSON) - if (fullJSON.ref.contains(refHead)) { - branch = fullJSON.ref.split(refHead).last() - } else { - branch = fullJSON.ref.split(refTags).last() - } + currentBuild.description = "Repo: ${fullJSON.repository.full_name} $branch" // Check project in map and start to work with it projects[projectName].each { Map project -> - currentBuild.displayName = "#${env.BUILD_ID} Run for branches" + currentBuild.displayName = "#${env.BUILD_ID} Run for all branches" + 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 + parameters: [ + string(name: 'PROJECT_NAME', value: projectName), + string(name: 'BRANCH_NAME', value: branch), + string(name: 'DATA_JSON', value: fullJSON.toString()) + ], + wait: false } } }