Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 6. Creating a secret for a webhook
You can create a secret that you can use with a generic, GitHub, or GitLab webhook to trigger application builds in a Git repository. Depending on the type of Git hosting platform that you use for your application code, the JWS Operator provides webhookSecrets:generic
, webhookSecrets:github
, and webhookSecrets:gitlab
parameters that you can use to specify the secret in the custom resource file for a web application.
Procedure
Create a Base64-encoded secret string.
For example:
echo -n "qwerty" | base64
echo -n "qwerty" | base64
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The preceding command encodes a plain-text string,
qwerty
, and displays the encoded string.For example:
cXdlcnR5
cXdlcnR5
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
secret.yaml
file that defines an object of kindSecret
.For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the preceding example,
jws-secret
is the name of the secret andcXdlcnR5
is the encoded secret string.To create the secret, enter the following command:
oc create -f secret.yaml
oc create -f secret.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The preceding command displays a message to confirm that the secret is created.
For example:
secret/jws-secret created
secret/jws-secret created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Based on the preceding example, you can set the
webhookSecrets:generic
parameter tojws-secret
.
Verification
Get the URL for the webhook:
oc describe BuildConfig | grep webhooks
oc describe BuildConfig | grep webhooks
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The preceding command generates the webhook URL in the following format:
https://<host>:<port>/apis/build.openshift.io/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/generic
https://<host>:<port>/apis/build.openshift.io/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/generic
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To send a request to the webhook, enter the following
curl
command:curl -k -X POST https://<host>:<port>/apis/build.openshift.io/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/generic
curl -k -X POST https://<host>:<port>/apis/build.openshift.io/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/generic
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the preceding command, replace
<host>
,<port>
,<namespace>
, and<name>
in the URL string with values that are appropriate for your environment. Replace<secret>
with the plain-text secret string (for example,qwerty
).The preceding command generates the following type of webhook response in JSON format and the build is triggered:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf a
User "system:anonymous" cannot create resource error
results, you can resolve this error either by adding unauthenticated users to thesystem:webhook
role binding or by creating a token and running thecurl
command.For example, to create a token and run the
curl
command:TOKEN=`oc create token builder` curl -H "Authorization: Bearer $TOKEN" -k -X POST https://<host>:<port>/apis/build.openshift.io/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/generic
TOKEN=`oc create token builder` curl -H "Authorization: Bearer $TOKEN" -k -X POST https://<host>:<port>/apis/build.openshift.io/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/generic
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you want to use the webhook in GitHub:
- In your GitHub project, select Settings > Webhooks > Add webhook.
- In the Payload URL field, add the URL.
-
Set the content type to
application/json
. - Disable SSL verification, if necessary.
- Click Add webhook.
For more information, see https://docs.openshift.com/container-platform/4.6/builds/triggering-builds-build-hooks.html.