Jenkins Freestyle Integration with Ansible and Hivel Webhook
This guide walks you through integrating Jenkins Freestyle pipelines with Hivel using an Ansible playbook and webhook reporting. You’ll learn how to trigger a playbook, capture build and stage metadata, and send it to Hivel’s API endpoint for monitoring and analytics.
🧰 Prerequisites
Make sure the following are set up on your Jenkins server (typically an EC2 instance):
✅ Jenkins installed and accessible
✅ Admin access to Jenkins UI
✅ Ansible installed and available in PATH
✅ Git configured (for Git metadata collection)
📦 Required Plugin
Install the following plugin:
Allows running Groovy scripts after a build
Required Credentials for Integration
During the integration, you'll need:
Organization ID (Generated in the Hivel application)
API Key (Generated in the Hivel application)
Retrieving Your Organization ID and API Key
Open the Hivel application and navigate to Integrations under the Settings.
Locate the Jenkins Integration card and click Connect.
Follow the given steps to start your integration.
By clicking on generate your Organization ID and API Key will be generated.
Use these fields while integrating with Jenkins. The steps for where to apply them are provided on the following page.
If you find it difficult, don’t worry! You can always reach out to us for assistance at [email protected].
Configuring Credentials in Jenkins
Log in to your Jenkins application.
From the side navigation, select Manage Jenkins.
Click on Credentials.
Click on global under Stores scoped to Jenkins
Choose Add Credentials - you will need to do this twice (once for the Organization ID and once for the API Key).
From the dropdown, select Secret text.
After selecting Secret text from the dropdown, fill in the details twice as follows:
Adding the API Key
ID: hivel-jenkins-api-key
Secret: {your API key} (copied from Hivel)
Description: This is the Jenkins API key from Hivel
Click Save
Repeat the process again for Adding the Organization ID
ID: hivel-org-id
Secret: {your Organization ID} (copied from Hivel)
Description: This is the Jenkins Organization ID from Hivel
Click Save
Once you have completed the above steps, your Jenkins Global Credentials should display the following entries:
Step 2: Bind Secrets in Job Configuration
Open your Freestyle job(pipeline in your dashboards)
Go to the Environment section
Check Use secret text(s) or file(s)
Click Add and bind the credentials like this:
HIVEL_ORG_ID
hivel-org-id
HIVEL_JENKINS_API_KEY
hivel-jenkins-api-key
Step 3: Install Ansible on Jenkins Server
Ensure Ansible is installed on the EC2/server where Jenkins is hosted.
For Amazon Linux 2:
sudo amazon-linux-extras enable ansible2
sudo yum install -y ansible
Run ansible --version on the Jenkins server to confirm installation.
Step 4: Add Build Step – Execute Ansible Playbook
Under Build Steps → Execute shell, add:
# Run Ansible playbook with JSON output
ANSIBLE_STDOUT_CALLBACK=json \
ansible-playbook ansible/dummy-stages.yml \
-i "localhost," --connection=local \
> ansible-output.json 2>&1 || true
This ensures that:
The playbook runs locally
Output is saved in JSON format to ansible-output.json
Even on errors, the script doesn’t fail the job
Step 5: Add Groovy Postbuild Script for Webhook Reporting
Under Post-build Actions:
Add → Groovy Postbuild
Paste the Groovy webhook script (Full Version) (provided below)
Uncheck the box labeled Use Groovy Sandbox
Approve script (open will appear once you enter script in groovy text box)
Save the job
if you check “use groovy sandbox” you might require to allow all script to be executed from settings section : go to Manage Jenkins → In-process Script Approval and approve the pending script.
Add groovy postbuild
{
"org_id": 12345,
"job_name": "freestyle-ansible-job",
"build_number": 12,
"status": "SUCCESS",
"build_url": "https://jenkins.example.com/job/freestyle-ansible-job/12/",
"start_time": "2025-04-08T10:12:00Z",
"end_time": "2025-04-08T10:12:45Z",
"duration": 45.25,
"git": {
"commit": "abc123...",
"branch": "main",
"author": "John Doe",
"author_email": "[email protected]",
"commit_message": "Add API integration",
"repository": "[email protected]:project/repo.git"
},
"triggered_by": "john.doe",
"stages": [
{
"stage_name": "Ensure packages installed",
"start_time": "2025-04-08T10:12:05.000000Z",
"end_time": "2025-04-08T10:12:10.000000Z",
"duration": 5.0,
"status": "SUCCESS",
"message": "All packages present"
}
]
}
Last updated
Was this helpful?