- Duration: 15 mins
- Audience: Developers, Architects, Devops
This section covers how to create an openshift pipeline build to trigger a jenkins slave and deploy our API in Openshift.
URLs:
Check with your instruction the GUID number of your current workshop environment. Replace the actual number on all the URLs where you find GUID.
Example in case of GUID = cluster-lhm8v.lhm8v.sandbox430:
https://console-openshift-console.apps.GUID.opentlc.com
becomes =>
https://console-openshift-console.apps.cluster-lhm8v.lhm8v.sandbox430.opentlc.com
Credentials:
Your username is your asigned user number. For example, if you are assigned user number 1, your username is:
user1
The password to login is always the same:
openshift
One of the prerequisites of this course is having an OC Cli already installed. if you don't have please go to Install Openshift CLI.
-
Once you have the Openshift Cli, you need to login, Open a new temrinal and type the following:
-
Open a browser window and navigate to:
oc login https://api.GUID.opentlc.com:6443 -p $PASSWORD -u $USER
Remember to replace the GUID with your environment value and your user number.
-
Once you have been loged in, you need to create a new build Jenkins pipeline Build.
oc new-build http://gogs.apps.GUID.opentlc.com/userX/todo-app.git#main --name=todo-app-pipeline -n user1
-
The first time it will fail, this is because we haven't set the variables needed for the pipeline to run.
-
If you want to see how it fails, please go to Builds section.
-
Choose the todo-app-pipeline build config, and then clic Builds tab
-
Select the failed build todo-app-pipeline-1 and see the error.
-
To set the variables type the following command:
oc set env bc/todo-app-pipeline GIT_REPO="http://gogs.apps.GUID.opentlc.com/userX/todo-app.git" \ GIT_BRANCH="main" PARAMS_OPENAPI_SPEC="src/openapi/openapi.yaml" \ APP_NAME="todo_api" \ PRIVATE_URL="http://todo-app-userX.apps.GUID.opentlc.com" \ INSTANCE="3scale-onprem" OCP_PROJECT="userX" \ SECRET_NAME="3scale-toolbox" TEST_ENDPOINT="/items" -n userX
-
Start the new build manually by running the follwing command:
oc start-build todo-app-pipeline -n userX
-
Once the pipeline has finished succesfully, you will see the pipeline as this:
-
You can access again 3scale admin portal to check if the new API has been created.
https://userX-admin.apps.GUID.opentlc.com
Note: If it fails try to guess why it is, Hint: Could be the account assigned to the application plan doesn't exists? Try to update your Jenkinsfile if it fails with the right number
-
Check if it's promoted until production. You can check it by clicking Integrations -> Configuration under Todo List (v1.0.0)
So, you want more? Have you tried to define the API using Oauth instead of api-key? Have you checked the Jenkinsfile, you could add the app deployment and the api together.
In this lab you have learned how to create builds of type pipeline and deploy APIs trough the API.