Skip to content

4.4. Building and Deploying With Jenkins

When to Use It

  • When running build and deployment as one combined flow
  • When you need run history and an approval process
  • When using a defined deployment method such as blue-green or rollback
  • When creating the build and deployment setup for a new application in one go

What Jenkins Is

It is a tool that runs several stages in order and keeps a record of them. It is also called a build automation server.

A single unit of work in Jenkins is called a Job. Running a Job executes the defined stages in order, and each run is numbered and recorded.

How It Differs From Building in the Console

Console (see 4.2)Jenkins
ScopeBuild to deployBuild, deploy, verify, and notify
TriggerWhen a button is selectedA button, a time, a source change, and others
Approval stageNoneCan be added
Deployment methodRolling updateBlue-green, canary, and others
HistoryKept per buildKept per Job run and retained longer
PreparationStraight from the screenJobs are created in advance

Both produce the same image. For a simple procedure the Console is faster; for a fixed, repeated procedure Jenkins is better.

Connecting to Jenkins

Open the Jenkins address in a browser. Ask your installation staff for the address, or go there from the Tools menu in the Console (see 9.3).

It uses the same integrated authentication as the Console, so if you are already signed in to the Console you enter without a separate sign-in.

The Job List

On connecting, the list of registered Jobs appears.

Jenkins Job list

The Jobs prepared in advance for the eGovFrame sample are as follows.

JobWhat it does
00-NEW-PROJECTCreates the build and deploy Jobs for a new application in one go
10-egov-helm-installPerforms the first installation with a Helm chart (see 9.1)
20-egov-buildBuilds the source with S2I and pushes the image to the registry
30-egov-deployDeploys the created image to the cluster
40-egov-rollbackReturns to the previous version
50-egov-blue-greenSwitches over using the blue-green method
60-egov-hpaRuns a deployment with autoscaling applied (see 3.5)
70-egov-argocd-deployDeploys through ArgoCD
99-egov-helm-uninstallRemoves what was installed

The leading numbers indicate the run order. For a first installation, proceed 10, then 20, then 30.

The marker on the left of each row is the last run result. A green check means success and red means failure. Selecting the run button at the far right runs it immediately.

Creating a New Project

When adding a new application, run the 00-NEW-PROJECT Job.

New project creation screen

The input fields are as follows.

FieldDescriptionExample
NAMESPACEThe namespace to deploy to. Created if absentegov
DEPLOYMENTThe application deployment namehomepage
GIT_URLThe Git repository address of the source to buildhttp://gitlab.../app.git
BASE_IMAGEThe base image for the S2I build and runtimeopenjdk17, tomcat9
HOSTThe external access addresshomepage-egov.apps...
NEXUS_URLThe internal library repository addresshttp://nexus...:8081

Maven and Gradle are supported as build tools.

Running it creates the following automatically.

AreaWhat is created
KubernetesNamespace, Deployment, Service, Ingress
JenkinsA build Job and a deploy Job dedicated to that application

You only have to run it once. After that, you use the build and deploy Jobs it created.

You can check the connections between the created resources on the Map screen in the Console (see 2.2).

Running the Build Job

Select 20-egov-build and run it.

Build Job screen

Running it proceeds in this order.

  1. Fetches the latest source from the Git repository.
  2. Compiles it with S2I and creates a container image.
  3. Pushes the image to the registry (Harbor).

Selecting a run number in Build History at the bottom left shows the console output (log). A build in progress continues live.

Failed runs keep a red marker. Select that number and look at the end of the log.

Running the Deploy Job

Once the build finishes, run 30-egov-deploy.

Deploy Job screen

The deploy Job applies the pushed image to the cluster's Deployment and waits until the new pods start successfully. If pods do not start, the Job also ends in failure, so the Job result alone tells you whether the deployment succeeded.

Choosing a Deployment Method

JobMethodCharacteristic
30-egov-deployRolling updateReplaces one at a time. The default
50-egov-blue-greenBlue-greenBrings up the whole new version first, then shifts traffic at once
70-egov-argocd-deployGitOpsDeploys based on definitions in the Git repository

Blue-green does not interrupt the service during the switch, and it can be reverted immediately if a problem appears. In exchange, it needs twice the resources during deployment.

Checking the Deployment Result

Once the deployment finishes, check it in the Console.

What to checkWhere
Whether pods startedWorkloads > Pods (see 3.1)
Whether the replica count is rightWorkloads > Deployments (see 3.2)
The deployed image tagThe containers on the deployment detail
The external access addressNetwork > Ingresses (see 5.1)
Resource connectionsMap (see 2.2)

Open the address shown on the Ingress in a browser and confirm that the application responds.

Rolling Back

There are two ways to roll back.

MethodCharacteristic
The 40-egov-rollback JobThe rollback is recorded in the Jenkins history
Deployment History in the ConsoleChoose a revision on screen and revert (see 3.2)

If you deployed with Jenkins, it is better to roll back with Jenkins. History stays in one place, which makes it easier to trace what happened later.

The Console is faster when you are in a hurry. However, that revert is not recorded in the Jenkins history, so deploying again from Jenkins later can return you to the state before the revert.