Create a Pipeline for Java Spring Boot
Deploying a Spring Boot App using Pipeline Strategy with Jenkings on Openshift
Create a fork of the
spring-clientrepository,Create a fork in your own GitHub organization, e.g. https://github.com//spring-client
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
Loginstage, Change the URL and the port to match your login command,
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, orGo 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
Systemview, select the dropdown forGlobal credentials (unrestricted),

Click
Add credentials,For
KindselectUsername with password,For
Usernameentertoken,For
Passwordpaste the OpenShift API token from the OpenShift web console login command,For
IDenteropenshift-login-api-token, which is the ID that the Jenkinsfile will look for,For
Descriptionenteropenshift 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
Noteaddgithub-access-token-for-jenkins-on-openshift,Select the scopes for
repo,read:repo_hook, anduser,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-clientapplication, 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 projectspringclient-nsexists in OpenShift,Go to OpenShift >
Cluster Console,Go to
Administration>Projects,Filter projects by
springclient-ns,If there is no such project, click
Create Projectto create it,
6. Create a Multibranch Pipeline using Blue Ocean,
In the Jenkins Dashboard, click
Open Blue Oceanto open the Blue Ocean editor,If the
Welcome to Jenkinspopup window shows, click theCreate a new Pipelinebutton, or click theNew Pipelinebutton in thePipelineswindow,

This will create a new
Multibranch Pipeline,Select the
GitHuboption,

In the
Connect to GitHubsection, 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-clientrepo,

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
Was this helpful?