Integrate JFrog with Dynatrace Cloud Automation
Integrating Dynatrace Cloud Automation with JFrog enables software engineering and operations teams to include pipeline runs in Cloud Automation sequences. This saves engineers time and increases confidence by providing both automated data-driven release decisions and problem remediation.
To integrate Dynatrace Cloud Automation with JFrog, follow the instructions below.
Prerequisites
JFrog
Dynatrace
JFrog
-
JFrog free SaaS DevOps subscription with JFrog Pipelines activated
-
Create a JFrog Pipelines incoming webhook that will be used by Cloud Automation to trigger a pipeline build
-
Add a JFrog Pipelines Generic Integration to create a secret for your Cloud Automation API token and URL.
Dynatrace
-
Create a Cloud Automation project with a shipyard file that has a custom task (for example,
release
) to trigger the JFrog webhook subscription. -
Add the JFrog incoming webhook URL obtained above as a Cloud Automation secret.
Set up the JFrog webhook subscription
Use case: Run a performance test or deploy code as part of a Cloud Automation sequence.
In JFrog
-
Adjust your JFrog pipeline to
- Start when the incoming webhook is triggered
- Send back a Cloud Automation finished event
The custom payload with the metadata configured can be accessed using an automatically built environment variable.
These items are part of the incoming webhook’s payload as sent by Cloud Automation:
project
stage
service
shkeptncontext
id
-
After the pipeline build is finished, JFrog notifies Cloud Automation so that the sequence can continue with the following JSON object:
{ "data":{ "project":"{PROJECT}", "stage":"{STAGE}", "service":"{SERVICE}", "status":"succeeded", "result":"pass" }, "source":"jfrog ", "specversion":"1.0", "type":"sh.keptn.event.{TASK NAME}.finished", "shkeptncontext":"{SHKEPTNCONTEXT}", "triggeredid":"{ID}" }
Example
Below is a complete example that assumes
- A JFrog webhook integration called
IncomingWebhookIntegration
- A JFrog generic integration called
cloudAutomationCred
with the Cloud Automation URL and API Token - A Cloud Automation sequence task called
release
that triggered this JFrog incoming webhook
Integrate the following code example into your existing pipeline definition:
resources:
- name: incoming_webhook
type: IncomingWebhook
configuration:
webhookName: IncomingWebhookIntegration
pipelines:
- name: release_demo_pipeline
steps:
- name: Processing_Incoming_Webhook
type: Bash
configuration:
affinityGroup: Cloud_Automation_Webhook
inputResources:
- name: incoming_webhook
execution:
onExecute:
- echo "$res_incoming_webhook_payload" | jq '.' > payload.json
- project=$(read_json payload.json "project")
- stage=$(read_json payload.json "stage")
- service=$(read_json payload.json "service")
- id=$(read_json payload.json "id")
- shkeptncontext=$(read_json payload.json "shkeptncontext")
- jfrogUrl=$(echo $step_url | cut -d? -f1)
- |
add_run_variables event_payload="$(cat <<-END
{
"data": {
"project": "$project",
"stage": "$stage",
"service": "$service",
"status": "succeeded",
"result": "pass",
"release": {
"jfrogUrl": "$jfrogUrl"
},
"labels": {
"jfrogUrl": "$jfrogUrl"
}
},
"source": "jfrog-pipeline",
"specversion": "1.0",
"type": "sh.keptn.event.release.finished",
"shkeptncontext": "$shkeptncontext",
"triggeredid": "$id"
}
END
)"
- name: Send_Finish_Event
type: Bash
configuration:
affinityGroup: Cloud_Automation_Webhook
integrations:
- name: cloudAutomationCred
inputSteps:
- name: Processing_Incoming_Webhook
execution:
onExecute:
- 'curl -X POST "$int_cloudAutomationCred_KEPTN_BASE_URL/api/v1/event" -H "accept: application/json" -H "x-token: $int_cloudAutomationCred_KEPTN_API_TOKEN" -H "Content-Type: application/json" -d "$event_payload"'
On the Cloud Automation bridge
-
Select your Cloud Automation project.
-
Select Settings, and then select Integrations.
-
Select webhook-service from the list, and then select Add subscription.
-
Enter the following values:
-
Task: Select a task (for example,
release
). -
Task suffix: Select
triggered
. -
Request method: Select
POST
. -
URL: Enter the incoming webhook URL concatenated with the secret you created in Prerequisites.
Example: If a webhook is
https://user123i:Password123@myproject-pipelines-api.jfrog.io/v1/projectIntegrations/9/hook
and your secret's name isWEBHOOKAUTH
, the URL value should behttps://{{.secret.jfrog.WEBHOOKAUTH}}@api.jfrog.io/v1/projectIntegrations/9/hook
.
-
-
Select Add custom header and enter the following values:
- For Name, enter
Content-Type
- For Value, enter
application/JSON
- For Name, enter
-
Enter a Custom payload.
Example:
{ "type": "{{.type}}", "project": "{{.data.project}}", "service": "{{.data.service}}", "stage": "{{.data.stage}}", "shkeptncontext": "{{.shkeptncontext}}", "id": "{{.id}}" }
-
Under Send started event, select
automatically
. -
Under Send finished event, select
by webhook receiver
. -
Select Create subscription.
Trigger a sequence
Cloud Automation triggers the JFrog pipeline whenever the defined task in the sequence is triggered.
To trigger the sequence, follow the steps below.
-
Create a file named
triggered-event.json
.Example:
{ "type": "sh.keptn.event.mystage.release.triggered", "specversion":"1.0", "source":"manual-trigger" "data":{ "project":"myproject", "stage":"mystage", "service":"myservice" } }
-
Send the event.
keptn send event --file triggered-event.json
After sending the event, you can
- Monitor the sequence progress on the Cloud Automation sequence page of the project
- Monitor the JFrog pipeline progress on the JFrog Web UI