Exercise 2 - Task 3 - Release Pipeline with Jenkins

2.3.1 Add Docker Build to Jenkins Pipeline

  1. Add another stage Package to the Jenkinsfile (Jenkins command stage)
  2. Add steps to that stage block to call your docker build task
    • use command sh to call command line commands
    • use gradle wrapper as follows to run a gradle task ./gradlew docker -i -s --no-daemon
      • -i means to show more log information
      • -s means to show stacktrace in case of errors
      • --no-daemon is important for CI server to not let the CI block any builds due to potential daemon overhead and troubles
  3. Test whether the pipeline runs successful so far

2.3.2 Add Docker Publish to Jenkins Pipeline

Caution:

  • There is currently a problem with dockerhub connectivity form our Jenkins - if somebody can solve the issue and succeeds this task to publish from Jenkins, you gonna win a sepcial price!
  • Maybe for today: just leave this task out and jump to the next section to get the release tagging working.

  • Add another stage Publish to the Jenkinsfile (Jenkins command stage)

  • Add steps to that block to call your docker publish task
    • you need to use the jenkins command withCredentials to use the credentials, that have been configured on the jenkins server for you already
    • inside the withCredentials-block you can call the docker login shell command and use the variables for username and password
    • finally you can call the gradle task dockerPush you automated already to publish the image to dockerhub
  • Test whether the pipeline runs successfully
    • there might be an issue with firewall or dockerhub configuration on the HSR jenkins server which might mean the login will fail.
    • do not loose time in that case and just uncomment the publishing command currently

2.3.3 Automate Tagging of Release for Push Button Releases

Now let's automate the the tagging of a release build with a proper semantic version, that can be entered as a parameter in the build pipeline to manually trigger a release build for a new release version.

  1. Here is an example pipeline for parametrizing your builds:

    pipeline {
        agent any
    
        parameters {
            string(name: 'releaseVersion', 
                   defaultValue: "", 
                   description: 'version number that will be used for the release and for tagging it in git repo.')
        }
    
        stages {
            stage('Create Release Tag') {
                when {
                    expression {
                        return params.releaseVersion != "";
                    }
                }
                steps {
                    echo "Tag for the release: ${params.releaseVersion}"
                    // TODO: create an annotated git tag
                }
            }   
    
            // all other stages go here ...
    
            stage('Push Release Tag') {
                    when {
                        expression {
                            return params.releaseVersion != "";
                        }
                    }
                steps {
                    echo "Push release tag: ${params.releaseVersion}"
                    // TODO: push the created tag
                }
            }
    
           }
    }
    

    Use this mechanism in your existing pipeline to provide a way to manually trigger a release build with a verison that will be tagged. For more information on parametrized builds, see: https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Parametrized-pipelines

  2. If the parameter is set then let jenkins first put a tag before running the release build
    • Use following git command to create the release tag: git tag -a <the-choosen-version-number> -m "Release Version <the-choosen-version-number>"
  3. If the build succeeds make sure that the tag will also be pushed to git
    • with this git shell command: git push --tags
  4. Test your release pipeline by choosing "Build with Parameters" in the Jenkins webapp on your branch and choose a version, e.g. 1.0.0 - maybe you are the first one?
    • For the parameters to appear you might have to run the pipeline once to update itself
  5. Check on gitlab that the tag was pushed properly: https://gitlab.dev.ifs.hsr.ch/mas-se-project-automation/project-automation/tags

Done?

  • Test your release on play with docker :-)
  • Still have some time? Implement another cool chatbot on your feature branch and quickly release it with the pipeline

results matching ""

    No results matching ""