From ce9e9cd67a17174b55578e59c3d4cf05350fa755 Mon Sep 17 00:00:00 2001 From: "aleksandr.vodyanov" Date: Tue, 30 Jan 2024 16:34:15 +0300 Subject: [PATCH] DO-143 code freeze (#15) Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/15 Co-authored-by: aleksandr.vodyanov Co-committed-by: aleksandr.vodyanov --- .../Release-activity/tavro/code_freeze.groovy | 56 ++++++++++ .../Release-activity/tavro/code_freeze.groovy | 102 ++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 jobs-dsl/jobs/Release-activity/tavro/code_freeze.groovy create mode 100644 pipelines/Release-activity/tavro/code_freeze.groovy diff --git a/jobs-dsl/jobs/Release-activity/tavro/code_freeze.groovy b/jobs-dsl/jobs/Release-activity/tavro/code_freeze.groovy new file mode 100644 index 0000000..f4be000 --- /dev/null +++ b/jobs-dsl/jobs/Release-activity/tavro/code_freeze.groovy @@ -0,0 +1,56 @@ +pipelineJob('Release-activity/tavro/code_freeze') { + logRotator { + numToKeep(10) + artifactNumToKeep(10) + } + + parameters { + choiceParameter { + name('SOURCE_BRANCH_NAME') + randomName('') + filterable(true) + filterLength(1) + script { + groovyScript { + fallbackScript { + script('') + sandbox(false) + } + script { + sandbox(false) + script( +"""import groovy.json.JsonSlurperClassic +def sout = new StringBuffer(), serr = new StringBuffer() +def proc = 'curl --connect-timeout 15 -u \${gitLogin}:\${gitPass} \${env.JENKINS_GIT_REPOSITORY_HTTP_URL}/api/v1/repos/\${repoName}/branches'.execute() +proc.consumeProcessOutput(sout, serr) +proc.waitForOrKill(5000) +JSONInfo = new JsonSlurperClassic().parseText(sout.toString()) +List branches = [] +JSONInfo.each{ branch -> +branches.add(branch.name) +} +return branches.sort() +""" + ) + } + } + } + choiceType('PT_SINGLE_SELECT') + } + } + + definition { + cpsScm { + scm { + git { + remote { + url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git") + credentials("${JENKINS_GIT_CREDENTIALS_HTTP}") + } + branch('master') + } + } + scriptPath('pipelines/Release-activity/tavro/code_freeze.groovy') + } + } +} diff --git a/pipelines/Release-activity/tavro/code_freeze.groovy b/pipelines/Release-activity/tavro/code_freeze.groovy new file mode 100644 index 0000000..d912706 --- /dev/null +++ b/pipelines/Release-activity/tavro/code_freeze.groovy @@ -0,0 +1,102 @@ +@Library('shared-lib') _ + +import tech.avroid.api.Gitea + +String apiRepoURL = "${env.JENKINS_GIT_REPOSITORY_URL}/api/v1/repos" +List parentJobs = ['jobs-dsl'] + + +withCredentials([usernamePassword(credentialsId: "${JENKINS_GIT_CREDENTIALS_HTTP}", + usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_USER_PASSWORD')]) { + gitLogin = GITEA_USER + gitPass = GITEA_USER_PASSWORD +} + +properties([ + buildDiscarder(logRotator(artifactNumToKeepStr: '10', + numToKeepStr: '10')), + disableConcurrentBuilds(), + parameters( + [[$class: 'ChoiceParameter', + choiceType: 'PT_SINGLE_SELECT', + filterLength: 1, + filterable: true, + name: 'RC_BRANCH_NAME', + script: [$class: 'GroovyScript', + script: [sandbox: false, script: """import groovy.json.JsonSlurperClassic +def sout = new StringBuffer(), serr = new StringBuffer() +def proc = 'curl --connect-timeout 15 -u ${gitLogin}:${gitPass} ${apiRepoURL}/TAVRO/TAVRO/branches'.execute() +proc.consumeProcessOutput(sout, serr) +proc.waitForOrKill(5000) +JSONInfo = new JsonSlurperClassic().parseText(sout.toString()) +List branches = [] +JSONInfo.each{ branch -> +branches.add(branch.name) +} +return branches.sort() +"""]], + ]] +)]) + +String releaseBranch = params.RC_BRANCH_NAME +releaseBranch = 'release' + releaseBranch.split('rc').last() + +//// Check if job triggered by parent job +//boolean isContainsParentJob = Info.isTriggeredByParent( +// script: this, +// parentJobs: parentJobs +//) +// +//if (isContainsParentJob) { +// currentBuild.result = 'SUCCESS' +// println("This job was triggered by one or more of following upstream jobs ${parentJobs}, so it will be exited without running the steps.") +// return +//} + +podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"), + yaml: ''' + apiVersion: v1 + kind: Pod + spec: + containers: + - name: linux + image: harbor.avroid.tech/devops/base-build-image:1.0 + tty: true + resources: + limits: + cpu: 300m + memory: 256Mi + requests: + cpu: 300m + memory: 256Mi + imagePullPolicy: Always + imagePullSecrets: + - name: harbor-registry-secret +''' +) { + node(POD_LABEL) { + stage('Create Release branch') { + currentBuild.description = "Build from ${params.SOURCE_BRANCH_NAME}" + Gitea tavroRepo = new Gitea(this, "${apiRepoURL}/TAVRO/TAVRO", "${env.JENKINS_GIT_CREDENTIALS_HTTP}") + boolean result = tavroRepo.createBranch(params.RC_BRANCH_NAME, releaseBranch) + + if (!result) { + println("Realease Branch already exists") + error() + } else { + stage('Create SharedLib tag') { + Gitea sharedLibRepo = new Gitea(this, + "${apiRepoURL}/DevOps/jenkins-shared-lib", + "${env.JENKINS_GIT_CREDENTIALS_HTTP}") + + sharedLibRepo.createTag('master', releaseBranch) + } + } + } + + stage('Run build') { + sleep(10) + build(job: "TAVRO Team/TAVRO/${releaseBranch}") + } + } +}