Create a Pipeline for Java Spring Boot

Deploying a Spring Boot App using Pipeline Strategy with Jenkings on Openshift

  1. Create a fork of the spring-client repository,

  2. Review Jenkinsfile,

    • Review the Jenkinsfile that is included in the Spring Client repository,

    • If you want an in-depth walk-through of the stages and steps in the Jenkinsfile, go to the Indepth Review of the Jenkinsfile,

    • Edit the Jenkinsfile,

    • In the Login stage, Change the URL and the port to match your login command,

  3. Configure Jenkins

    • Go to the OpenShift web console,

      • From the logged in user profile dropdown, click the Copy Login Command,

  • The command should look like,

      oc login https://<your-openshift-url>:<your-openshift-port> --token=<your-openshift-api-token>
  • Copy the OpenShift API token value, e.g. aaHYcMwUyyusfNaS45aAiQer_Kas1YUa45YTA2AxsNI,

  • Go to the Jenkins Administration dashboard,

  • Click Credentials, or

  • Go to Jenkins > Manage Jenkins > Configure Credentials

  • The Jenkinsfile expects the OpenShift API token credential to be available named openshift-login-api-token,

  • Go to Credentials > System,

  • In the System view, select the dropdown for Global credentials (unrestricted),

  • Click Add credentials,

    • For Kind select Username with password,

    • For Username enter token,

    • For Password paste the OpenShift API token from the OpenShift web console login command,

    • For ID enter openshift-login-api-token, which is the ID that the Jenkinsfile will look for,

    • For Description enter openshift login api token,

    • Click OK,

4. Create a Personal Access Token to Access the Github API

  • Go to your Github account > Settings > Developer settings > Personal access tokens,

  • Click Generate new token,

  • Under Note add github-access-token-for-jenkins-on-openshift,

  • Select the scopes for repo, read:repo_hook, and user,

  • Click Generate token,

  • Copy the token, we need it to create our Jenkins pipeline,

5. Make sure a project springclient-ns exists in OpenShift,

  • From the cloud shell, oc new-project springclient-ns ,

  • Before deploying the spring-client application, the Jenkinsfile defines a step to delete and create a project. The delete step causes an error when the project it tries to delete is missing, so make sure the project springclient-ns exists in OpenShift,

  • Go to OpenShift > Cluster Console,

  • Go to Administration > Projects,

  • Filter projects by springclient-ns,

  • If there is no such project, click Create Project to create it,

6. Create a Multibranch Pipeline using Blue Ocean,

  • In the Jenkins Dashboard, click Open Blue Ocean to open the Blue Ocean editor,

  • If the Welcome to Jenkins popup window shows, click the Create a new Pipeline button, or click the New Pipeline button in the Pipelines window,

  • This will create a new Multibranch Pipeline,

  • Select the GitHub option,

  • In the Connect to GitHub section, paste the personal access token you created in your Github account,

  • Click Connect,

  • Select the organization to where you forked the Spring Client repository,

  • Search for and select the spring-client repo,

  • Click Create Pipeline,

  • When the pipeline creation is completed, a build is triggered automatically,

  • Immediately, a build is triggered,

  • You should see a successful build of the pipeline,

  • If an error occurs, you can debug the pipeline,

  • A red cross on a stage, will indicate the pipeline broke in that stage,

  • Unfold the step in the stage, to see the log output,

  • Any update to the Github repository, e.g. a push to update the Jenkinsfile, source code of the Spring Boot application, or the README.md file, will trigger a new build of the pipeline,

  • If you're interested, review the pipeline settings:

    • Click the Configure option,

    • Review the settings,

  • Get the route

  • Test the deployment,

$ ROUTE="$(oc get route springclient -o json | jq -r '.spec .host')"
$ curl -X GET http://$ROUTE/api/hello?name=you
{ "message" : "Hello you" }

Last updated