Creating Pipelines
Last updated
Was this helpful?
Last updated
Was this helpful?
After you open the Registry page, select the region as Dallas.
Go to the Namespaces tab.
Click to Create button, and name it jenkins-workshop-<unique-name>
.Namespace names should be unique across the region.
Go to Cloud Shell Tab. Click to +
sign to open a new session.
Look on the top right and be sure that
Location is Dallas
Current account is your personal account (not DevAdv account)
If it is not, login with ibmcloud login -a cloud.ibm.com -r us-south
then enter your ibm cloud email and password. Select the first account (your personal account, the one does not includes IBM)
Enter ibmcloud target
to be sure. You should see your personal account's name and us-south region.
Enter ibmcloud iam api-key-create container-registry-key
Copy the apikey and note it to a notepad. (write container registry to not forget for which task you created it)
The infos we will need are:
us-south for region (us.icr.io)
jenkins-workspace as namespace name
apikey to access registry
Open new terminal session
login with ibmcloud login -a cloud.ibm.com -r us-south
then enter your ibm cloud email and password again. This time select IBM provided account.
Enter ibmcloud iam api-key-create container-registry-key
Copy the apikey and note it to a notepad. (write kubernetes to not forget for which task you created it)
We will need 3 secrets to use in our pipeline
Secret for pushing to container registry
Secret for kubernetes deployment
Secret for pulling image to kubernetes
Open a new terminal in IBM Cloud shell.
Check targeted account, if it is the one provided from IBM, you don't need to login. If it is not, login as explained above.
Access to your cluster as explained in here.
This secret will be used when configuring private registry access in jenkins job.
This secret will be used when configuring kubernetes cluster in jenkins job.
This secret will be added to default namespace and will be use inn pod template. When pod tries to pull the image from your private registry, it will use this secret.
It is important to not change the secret name, otherwise, deployment.yml should change too.
Go to Jenkins server tab that we have opened in the first section. If you have closed accidentally, Open you IBM Cloud Shell tab, press the eye
button and then click to 8080.
Username is : admin
Password is : you have wrote it down in the first section.
On the left menu, you will see New Item. Click on that item.
Enter your pipeline name.
Select Pipeline item below
Click OK.
The options on the pipelines are not these workshop's topic. Scroll down to Pipeline section.
Here we will write our Jenkins script.
Since we are using Kubernetes, we will use kubernetes plugin. This is already installed and configured. We will check it after creating the pipeline.
This template will describe the pod that will be created by Jenkins.
Cloud: kubernetes. This is preconfigured for us in the jenkins installation. We will show this configuration after the pipeline.
Label: This is the tracking mechanism in Jenkins. We will target this pod later in the pipeline using this label.
Containers: this is the section we define containers in the pod. It uses ContainerTemplate
volumes: Volume binding configuration in kubernetes pod spec. Binding docker socket to pod so we can build docker containers in build stage.
node
script tells jenkins to target a pod. "workshop"
is the label that we want jenkins to create for this pipeline.
stage: we define the stage name here.
git url: this script helps us to clone the git repo to our workdir.
container: we tell which container will be used for this stage. this is one of the containers we defined in podTemplate. We use the name info of the container
In this container, we are using a special container created for ibmcloud cli automation. More detailed info is here.
sh 'ibmcloud login -a cloud.ibm.com -r
us-south
--apikey ${REGISTRY_TOKEN}'
just be sure with the region. This region is the one your container registry is created in.
sh 'ibmcloud cr build -t
us.icr.io
/volaka/application:${BUILD_ID} .'
just be sure with the registry address. You can find more information about regions and urls in container registry docs.
Don't forget to check your region in login command. This is the region your kubernetes cluster is created in.
Replace your cluster name in the second command.
Check those parameters in third command. sed command replaces the appropriate line with your image name.
us.icr.io (your image registry, where you pushed in build stage)
your registry namespace
your application name.
Fourth command applies the deployment.yml to your kubernetes cluster and deploys your application.
You should have something similar to the following file
Go to your Kubernetes Cluster overview page in IBM Cloud Web.
Select your cluster.
If you don't see any clusters, check your account from top left and be sure that you are not in your personal account.
Go to worker nodes tab from the left menu and copy the public ip.
Open the Kubernetes Dashboard to look for the service port.
In my case, I can access to my application via 169.50.53.68:31978