[DO-200] Add platformng release activities (!25)
Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/25 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>
This commit is contained in:
committed by
Aleksandr Vodyanov
parent
1ad918c929
commit
64ed0dc98e
68
jobs-dsl/jobs/Release-activity/platformng.groovy
Normal file
68
jobs-dsl/jobs/Release-activity/platformng.groovy
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
pipelineJob('Release-activity/Platformng') {
|
||||||
|
logRotator {
|
||||||
|
numToKeep(10)
|
||||||
|
artifactNumToKeep(10)
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
choice {
|
||||||
|
name('BRANCH_TYPE')
|
||||||
|
choices(['Release', 'RC'])
|
||||||
|
description('Select one of branch types')
|
||||||
|
}
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
string {
|
||||||
|
name('VERSION')
|
||||||
|
defaultValue('')
|
||||||
|
description('Release version eg. (1.4 or 1.4-demo)')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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/platformng.groovy')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
103
pipelines/Release-activity/platformng.groovy
Normal file
103
pipelines/Release-activity/platformng.groovy
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
@Library('shared-lib') _
|
||||||
|
|
||||||
|
import tech.avroid.api.Gitea
|
||||||
|
|
||||||
|
String branch
|
||||||
|
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([
|
||||||
|
choice(
|
||||||
|
name: 'BRANCH_TYPE',
|
||||||
|
choices: ['Release', 'RC'],
|
||||||
|
description: 'Select one of branch types'
|
||||||
|
),
|
||||||
|
[$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}/BBL/platformng/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: 'VERSION', defaultValue: '', description: 'Release and RC version eg. 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: getPodTemplate('alpine')) {
|
||||||
|
node(POD_LABEL) {
|
||||||
|
try {
|
||||||
|
stage('Create branch') {
|
||||||
|
currentBuild.description = "Build from ${params.SOURCE_BRANCH_NAME}"
|
||||||
|
String versionPattern = /^\d+\.\d+.*/
|
||||||
|
Gitea tavroRepo = new Gitea(this, "${apiRepoURL}/BBL/platformng", "${env.JENKINS_GIT_CREDENTIALS_HTTP}")
|
||||||
|
branch = params.BRANCH_TYPE.toLowerCase() + params.VERSION
|
||||||
|
println "Branch name: ${branch}"
|
||||||
|
|
||||||
|
if (!params.VERSION.matches(versionPattern) {
|
||||||
|
println('You must specify correct version, see description!')
|
||||||
|
error()
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean result = tavroRepo.createBranch(params.SOURCE_BRANCH_NAME, branch)
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
println("Branch doesn't create, maybe ${branch} already exists")
|
||||||
|
error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.BRANCH_TYPE == 'Release') {
|
||||||
|
stage('Create SharedLib tag') {
|
||||||
|
Gitea sharedLibRepo = new Gitea(this,
|
||||||
|
"${apiRepoURL}/DevOps/jenkins-shared-lib",
|
||||||
|
"${env.JENKINS_GIT_CREDENTIALS_HTTP}")
|
||||||
|
|
||||||
|
sharedLibRepo.createTag('master', "platformng_${branch}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Run build') {
|
||||||
|
sleep(5)
|
||||||
|
build(job: "BBL Team/platformng/${branch}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
echo 'ERROR: ' + err.getMessage()
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
|
} finally {
|
||||||
|
cleanWs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"), yaml: g
|
|||||||
"${apiRepoURL}/DevOps/jenkins-shared-lib",
|
"${apiRepoURL}/DevOps/jenkins-shared-lib",
|
||||||
"${env.JENKINS_GIT_CREDENTIALS_HTTP}")
|
"${env.JENKINS_GIT_CREDENTIALS_HTTP}")
|
||||||
|
|
||||||
sharedLibRepo.createTag('master', branch)
|
sharedLibRepo.createTag('master', "tavro_${branch}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user