Files
jenkins-pipelines/pipelines/Release-activity/tavro/feature_freeze.groovy
aleksandr.vodyanov 9c78fca70a DO-143_feature_freeze (#4)
+ Add Feeature freeze for tavro

Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/4
Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.tech>
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Co-committed-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
2023-11-16 17:33:49 +03:00

108 lines
3.4 KiB
Groovy

@Library('shared-lib') _
import tech.avroid.api.Gitea
String rcBranch
String gitToken
String apiRepoURL = "${env.JENKINS_GIT_REPOSITORY_URL}/api/v1/repos/TAVRO/TAVRO"
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: 'SOURCE_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}/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(name: 'RC_VERSION', defaultValue: '', description: 'Release version eg. (1.4 or 1.4-demo)'),
booleanParam(name: 'TEST_RC_BRANCH',
defaultValue: false,
description: 'Test RC branch or no. If value is true, branch will be looks as test_rc_1.4')
]
)
])
// Check if job triggered by parent job
boolean isContainsParentJob = parentJobs.any {job -> currentBuild.upstreamBuilds.projectName.contains(job) }
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 RC branch') {
currentBuild.description = "Build from ${params.SOURCE_BRANCH_NAME}"
Gitea tavroRepo = new Gitea(this, apiRepoURL, "${env.JENKINS_GIT_CREDENTIALS_HTTP}")
String versionPattern = /^\d+\.\d+.*/
String rcPrefix = 'rc'
String rcTest = params.TEST_RC_BRANCH == true ? 'test_' : ''
rcBranch = rcTest + rcPrefix + params.RC_VERSION
if (!params.RC_VERSION.matches(versionPattern)) {
println('You must specify correct version, see description!')
error()
}
boolean result = tavroRepo.createBranch(params.SOURCE_BRANCH_NAME, rcBranch)
if (!result) {
println("RC Branch doesn't create, maybe ${rcBranch} already exists")
error()
}
}
stage('Run build') {
sleep(10)
build(job: "TAVRO Team/TAVRO/${rcBranch}")
}
}
}