SHARE
TWEET

vladislavnaumov




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- /**
- * pipeline for promote kaas openstack cluster-api docker images
- * CREDENTIALS_ID - gerrit credentials id
- * GERRIT_HOST - Gerrit host
- * KAAS_PIPELINE_REFSPEC - Refspec for kaas related pipelines, for testing additional pipeline changes, generally using GERRIT_REFSPEC
- * GERRIT_REFSPEC - Parameter also used for fetching groovy pipeline from kaas repo [KAAS_PIPELINE_REFSPEC],
- * default value used in case of non-triggered run, otherwise gerrit trigger will overwrite it
- * DRY_RUN - (bool) if true, dont push charts in PROD
- *
- * dockerRegistry - url to docker registry
- * devDockerRepo - url to dev docker repo
- * prodDockerRepo - url to prod docker repo [WARNING! prod artifactory promoting temporally disabled until KaaS release, promoting only in dev*]
- **/
- def common = new com.mirantis.mk.Common()
- def jUtils = new com.mirantis.mk.JenkinsUtils()
- def gerrit = new com.mirantis.mk.Gerrit()
- def artifactory = new com.mirantis.mcp.MCPArtifactory()
- def artifactoryServer = Artifactory.server('mcp-ci')
- def buildInfo = Artifactory.newBuildInfo()
- jobCatchedErrors = 'No build errors'
- dryRun = env.DRY_RUN ? env.DRY_RUN.toBoolean() : false
- // Artifact repo management
- dockerRegistry = 'docker-kaas-local.docker.mirantis.net'
- devDockerRepo = 'docker-dev-kaas-local'
- prodDockerRepo = 'docker-kaas-local'
- node('docker') {
- def workspace = common.getWorkspace()
- // Define Jenkins user id's for docker operations
- def jenkinsUID = common.getJenkinsUid()
- def jenkinsGID = common.getJenkinsGid()
- jenkinsUser = "${jenkinsUID}:${jenkinsGID}"
- //avoid root-owned docker artifacts before kaasLibrary scm
- sh(script: """\
- docker run --rm \
- -v ${workspace}:/code \
- busybox sh -c 'chown -R ${jenkinsUser} /code'
- """
- )
- // Import external kaas groovy library
- stage('Getting kaas-libraries') {
- checkout scm
- baseKaas = load 'hack/backend/kaasLibrary.groovy'
- }
- // Check if dependency jobs passed successfully
- depsResult = jUtils.checkDependencyJobs()
- if (!depsResult.status){
- return
- }
- // Docker image parameters
- def imageTag = ''
- def promoteTag = 'NO_TAG'
- def imageRepo = 'core'
- try {
- stage('Checkout') {
- if (GERRIT_EVENT_TYPE == 'ref-updated' ){
- common.warningMsg('Gerrit-triggered run. Tagged release from tag refspec of mirantis branch in kaas/cluster-api-provider-openstack repo')
- gerrit.gerritPatchsetCheckout('ssh://mcp-jenkins@gerrit.mcp.mirantis.net:29418/kaas/cluster-api-provider-openstack' , 'mirantis', GERRIT_REFNAME, CREDENTIALS_ID)
- } else {
- common.warningMsg("Gerrit-triggered run. Product code and groovy pipeline fetched from ${GERRIT_REFSPEC} in kaas/cluster-api-provider-openstack repo")
- gerrit.gerritPatchsetCheckout([
- credentialsId: CREDENTIALS_ID,
- withWipeOut: true,
- ])
- }
- }
- stage('Getting valid image tags and names for promote') {
- imageNamesList = sh(script: "make DEST=${workspace} GOOS=linux image-names", returnStdout: true).trim().split().collect{ it as String }
- imageTag = sh(script: "make DEST=${workspace} GOOS=linux version", returnStdout: true).trim()
- if (GERRIT_EVENT_TYPE == 'ref-updated'){
- def gitTag = GERRIT_REFNAME.replace('refs/tags/v', '').trim()
- def additionalReleaseImages = ['kind-cache', 'squid-cache']
- imageNamesList.addAll(additionalReleaseImages)
- imageTag = gitTag
- common.warningMsg("""PAY ATTENTION: Tagged release!
- ${additionalReleaseImages} images will be promoted.
- all release artifacts will be tagged with git tag ${imageTag} instead of 'make version'""")
- }
- promoteTag = imageTag
- }
- stage('Promote KaaS product images in PROD') {
- imageNamesList.each {
- try {
- common.infoMsg("Image ${it} will be promoted in production repo with tag ${imageTag}")
- if (dryRun) {
- common.warningMsg('DRY_RUN enabled, skipping push')
- } else {
- artifactory.promoteDockerArtifact(artifactoryServer.getUrl(),
- devDockerRepo,
- prodDockerRepo,
- "${imageRepo}/${it}",
- imageTag,
- promoteTag,
- true)
- }
- } catch (e) {
- jobCatchedErrors = jobCatchedErrors + "${e.message}\n"
- currentBuild.result = 'UNSTABLE'
- common.errorMsg("Some images may not be promoted properly. Errors during promotion process: ${e}")
- }
- }
- }
- // PAY attention, below stages is additional and may be removed in future
- if (GERRIT_EVENT_TYPE == 'ref-updated'){
- // Additional images will be built only in case of tagged release, otherwise we keep previous `latest` versions in repos
- stage('Promote custom images for internal purposes') {
- try {
- common.infoMsg("""Latest test/frontend ui-infra image
- will be promoted in ${prodDockerRepo} repo with tag ${imageTag}
- for integration testing.""")
- sh('docker pull docker-dev-kaas-local.docker.mirantis.net/core/test/frontend:latest')
- sh("docker tag docker-dev-kaas-local.docker.mirantis.net/core/test/frontend:latest ${dockerRegistry}/${imageRepo}/test/frontend:${imageTag}")
- if (dryRun) {
- common.warningMsg('DRY_RUN enabled, skipping push')
- } else {
- artifactory.uploadImageToArtifactory(
- artifactoryServer,
- dockerRegistry,
- "${imageRepo}/test/frontend",
- imageTag,
- prodDockerRepo,
- buildInfo)
- }
- common.infoMsg("kind-cache image will be promoted in ${devDockerRepo} repo with tag: latest")
- if (dryRun) {
- common.warningMsg('DRY_RUN enabled, skipping push')
- } else {
- artifactory.promoteDockerArtifact(artifactoryServer.getUrl(),
- devDockerRepo,
- devDockerRepo,
- "${imageRepo}/kind-cache",
- imageTag,
- 'latest',
- true)
- }
- } catch (e) {
- jobCatchedErrors = jobCatchedErrors + "${e.message}\n"
- common.errorMsg("Main build actions passed successfully, additional steps failed due: ${e}")
- currentBuild.result = 'UNSTABLE'
- }
- }
- }
- } catch (e) {
- // If there was an error or exception thrown, the build failed
- currentBuild.result = 'FAILURE'
- jobCatchedErrors = jobCatchedErrors + "${e.message}\n"
- throw e
- } finally {
- def imageFullNamesList = []
- imageNamesList.each {
- imageFullNamesList.add("${dockerRegistry}/${imageRepo}/${it}:${imageTag}")
- }
- def prettyHtmlPackages = ''
- if (currentBuild.result != 'FAILURE'){
- imageFullNamesList.each {
- prettyHtmlPackages = "${prettyHtmlPackages} docker pull ${it}<br/>"
- }
- }
- currentBuild.description = """
- <p>
- <b>DRY RUN enabled: </b>${dryRun}<br/>
- <b>Images were built</b>:<br/>
- ${prettyHtmlPackages}<br/>
- <b>Errors</b>: ${jobCatchedErrors}<br/>
- </p>
- """
- stage('Cleanup') {
- // cleanup workspace
- deleteDir()
- }
- }
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.