$ oc get bc/ostoy-microservice -o=jsonpath='{.spec.triggers..github.secret}'
Automatically trigger a build and deploy anytime you change the source code by using a webhook. For more information about this process, see Triggering Builds.
To get the GitHub webhook trigger secret, in your terminal, run the following command:
$ oc get bc/ostoy-microservice -o=jsonpath='{.spec.triggers..github.secret}'
`o_3x9M1qoI2Wj_cz1WiK`
You need to use this secret in a later step in this process. |
To get the GitHub webhook trigger URL from the OSToy’s buildconfig, run the following command:
$ oc describe bc/ostoy-microservice
[...]
Webhook GitHub:
URL: https://api.demo1234.openshift.com:443/apis/build.openshift.io/v1/namespaces/ostoy-s2i/buildconfigs/ostoy/webhooks/<secret>/github
[...]
In the GitHub webhook URL, replace the <secret>
text with the secret you retrieved. Your URL will resemble the following example output:
https://api.demo1234.openshift.com:443/apis/build.openshift.io/v1/namespaces/ostoy-s2i/buildconfigs/ostoy-microservice/webhooks/o_3x9M1qoI2Wj_czR1WiK/github
Setup the webhook URL in GitHub repository.
In your repository, click Settings > Webhooks > Add webhook.
Paste the GitHub webhook URL with the secret
included into the "Payload URL" field.
Change the "Content type" to application/json
.
Click the Add webhook button.
You should see a message from GitHub stating that your webhook was successfully configured. Now, whenever you push a change to your GitHub repository, a new build automatically starts, and upon a successful build, a new deployment starts.
Now, make a change in the source code. Any changes automatically trigger a build and deployment. In this example, the colors that denote the status of your OSToy app are selected randomly. To test the configuration, change the box to only display grayscale.
Go to the source code in your repository https://github.com/<username>/ostoy/blob/master/microservice/app.js.
Edit the file.
Comment out line 8 (containing let randomColor = getRandomColor();
).
Uncomment line 9 (containing let randomColor = getRandomGrayScaleColor();
).
7 app.get('/', function(request, response) {
8 //let randomColor = getRandomColor(); // <-- comment this
9 let randomColor = getRandomGrayScaleColor(); // <-- uncomment this
10
11 response.writeHead(200, {'Content-Type': 'application/json'});
Enter a message for the update, such as "changed box to grayscale colors".
Click Commit at the bottom to commit the changes to the main branch.
In your cluster’s web UI, click Builds > Builds to determine the status of the build. After this build is completed, the deployment begins. You can also check the status by running oc status
in your terminal.
After the deployment has finished, return to the OSToy application in your browser. Access the Networking menu item on the left. The box color is now limited to grayscale colors only.