Connect Your Application
Visit Connected Applications on the sidebar. Click on the Connect button for Jenkins.
The integration between Valven Atlas and Jenkins mostly requires configurations on the Jenkins side. In terms of integration, two Jenkins plugins are used to send webhooks from Gihub, Gitlab, and Bitbucket to Valven Atlas.
- HTTP Request (HTTP Request)
- Generic Webhook Trigger (Webhook Trigger)
As long as the incoming payloads are unchanged and only webhooks related to releases deployed to production are sent to Atlas, you can use any plugin and/or script you want.
Webhooks for releases that will not be installed in production should not be sent to Valven Atlas!
Once the connect button is clicked in Valven Atlas Connected Applications, a pop-up with guidance to complete the integration and a UUID will be presented for the webhook configurations in Gihub, Gitlab, and Bitbucket.
Once you click the "Save" button, we will assume the configuration on the Jenkins side is completed and show the connected Jenkins section.
HTTP Request Details
HTTP request details should be registered to establish the communication between Valven Atlas and Jenkins and enable Jenkins to share the deployment details with Valven Atlas.
Configuring Jenkins Pipeline
Each organization can keep different pipelines for their Jenkins automation. Therefore depending on your pipeline, you must add the following Jenkins pipeline section to your existing pipeline.
The token in GenericTrigger settings is used to determine the authenticity of the webhook traffic between the Git provider and Jenkins. The token you enter here should be added as a parameter to the Webhook URL in GitHub/GitLab/Bitbucket according to the instructions you will find later in this section.
pipeline{
agent any
triggers{
GenericTrigger(
genericVariables: [[key: 'POST_CONTENT', value: '$']],
causeString: 'Triggered by a remote git vendor',
token: 'SecretToken',
tokenCredentialId: '',
regexpFilterText: '',
regexpFilterExpression: ''
)
}
...
post {
success {
script{
if (currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) != null) {
echo "Build triggered by user"
def GIT_TAG = env.GIT_TAG ?: ''
def PULL_REQUEST = env.PR_ID ?: ''
def PAYLOAD = """
{
"author":"$BUILD_USER_EMAIL",
"branch":"$GIT_BRANCH",
"hash":"$GIT_COMMIT",
"tag":"$GIT_TAG",
"pull_request":"$PULL_REQUEST",
"url":"$GIT_URL"
}
"""
httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', customHeaders: [[maskValue: false, name: 'jenkins-event-type', value: 'workflow-completed']], httpMode: 'POST', ignoreSslErrors: true, requestBody: PAYLOAD, responseHandle: 'NONE', url: 'https://atlas-webhook.valven.com/api/deployment/UUID', wrapAsMultipart: false
} else {
echo "Build triggered by webhook"
def POST_CONTENT = env.POST_CONTENT ?: '{ "status": "failed" }'
def PAYLOAD = "$POST_CONTENT"
echo "PAYLOAD: $PAYLOAD"
httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', customHeaders: [[maskValue: false, name: 'jenkins-event-type', value: 'workflow-completed']], httpMode: 'POST', ignoreSslErrors: true, requestBody: PAYLOAD, responseHandle: 'NONE', url: 'https://atlas-webhook.valven.com/api/deployment/UUID', wrapAsMultipart: false
}
}
}
}
}
Related Parameters:
token: Here you will set a secret token to allow Jenkins to accept the trigger requests from GitHub, GitLab, and Bitbucket. Otherwise, Jenkins will ignore incoming requests. Get your token.
UUID: The UUID stated as blue in the pipeline should be replaced with the UUID obtained from Atlas for Jenkins. This step is important for Atlas to recognize that the incoming request is coming from you.
In case you send data in a different way than in the example, here are the issues you need to pay attention to;
Type of request: POST
Custom Header: You should perform the request with a custom header named 'jenkins-event-type' and 'workflow-completed' as value.
Managing WebHooks
Depending on your Git service provider, go to the webhook options in the settings of your project and make the necessary changes and additions using the following examples for the currently supported 3 Git providers;
- GitLab
- GitHub
- Bitbucket
Managing Webhooks will require you to obtain a SecretToken to establish communication between your Git provider and Jenkins you can learn how to obtain your Secret Token here. Replace the <SecretToken> parameter at the end of your respective Git provider URL with the obtained token.
GitLab Webhook Configuration
In order to complete the configuration from your GitLab, ensure that the configuration meets the following visual.
Related Parameters:
URL: https://jenkins.company.com/generic-webhook-trigger/invoke?token=<SecretToken>
Trigger: You can choose Tag push events or Merge request events depending on how you want to create the versions you intend to install on production.
GitHub Webhook Configuration
In order to complete the configuration from your GitHub, ensure that the configuration meets the following visual.
Related Parameters:
Payload URL: https://jenkins.company.com/generic-webhook-trigger/invoke?token=<SecretToken>
Content type: application/json
Trigger: You can choose Branch or tag creation events or pull request events depending on how you want to create the versions you intend to install on production.
Bitbucket Webhook Configuration
In order to complete the configuration from your Bitbucket, ensure that the configuration meets the following visual.
Related Parameters:
URL: https://jenkins.company.com/generic-webhook-trigger/invoke?token=<SecretToken>
Trigger: You can choose Repository >Push events or Pull request > Merged events depending on how you want to create the versions you intend to install on production.
Comments
0 comments
Article is closed for comments.