TerraformCLI icon
Docker icon
AnsibleCLI icon
JobBuild icon
Sequential icon
Request icon
Assert icon
DiscordIncomingWebhook icon

Cross-Stack Pipeline with Terraform, Ansible, and Jenkins

Orchestrate a Terraform, Ansible, and Jenkins pipeline in Kestra. Provision a fleet, apply a playbook, run a Jenkins test, poll to completion, and alert Discord.

Categories
Infrastructure

Stitch infrastructure provisioning, configuration management, and CI testing into one governed pipeline. This blueprint chains Terraform, Ansible, and Jenkins in a single Kestra flow: Terraform provisions a test fleet, Ansible applies the baseline configuration, Kestra triggers a Jenkins test job, then polls Jenkins until the build reaches a terminal result and reports the outcome to Discord. It solves the classic cross-tool handoff problem, where Terraform, Ansible, and Jenkins each have their own runner and scheduler but nothing coordinates them end to end or surfaces a single pass or fail signal.

How it works

  1. terraform_apply (io.kestra.plugin.terraform.cli.TerraformCLI) runs terraform init then terraform apply -auto-approve inside a hashicorp/terraform Docker task runner to provision the test fleet.
  2. ansible_configure (io.kestra.plugin.ansible.cli.AnsibleCLI) runs ansible-playbook against the inventory inside a cytopia/ansible Docker task runner to apply the baseline.
  3. jenkins_test (io.kestra.plugin.jenkins.JobBuild) triggers the configured Jenkins test job using the serverUrl and jobName inputs with Basic Auth.
  4. wait_for_jenkins (io.kestra.plugin.core.flow.Sequential) wraps an HTTP test_status call to the Jenkins lastBuild/api/json endpoint and an assert_test_done check (io.kestra.plugin.core.execution.Assert). A constant retry (PT15S, up to 80 attempts) re-runs the block until result is non-empty.
  5. notify (io.kestra.plugin.discord.DiscordIncomingWebhook) posts the chain outcome to Discord; an alert_on_failure error handler posts a failure message if any step fails.

What you get

  • A single execution that provisions, configures, tests, and reports across three tools.
  • Reliable polling of Jenkins via lastBuild rather than a fragile fixed wait.
  • Per-step retries that do not cascade: an Ansible retry never re-runs Terraform, and a Jenkins poll retry never re-runs Ansible.
  • Discord notifications on both success and failure.

Who it's for

  • Platform and DevOps engineers coordinating IaC, config management, and CI.
  • SRE teams that want one auditable pass or fail signal across the stack.
  • Anyone replacing brittle shell glue between Terraform, Ansible, and Jenkins.

Why orchestrate this with Kestra

Terraform, Ansible, and Jenkins each ship their own runner and scheduler, but none of them coordinates the others or gives you one lineage view across the whole chain. Kestra adds event and schedule triggers, per-step retries (the wait_for_jenkins block polls Jenkins safely), a single execution timeline with full lineage, and declarative YAML you can version and review. The gap Jenkins's own scheduler cannot fill: it has no awareness of the Terraform and Ansible steps that must succeed first, and no native way to gate, retry, and report on them as one unit.

Prerequisites

  • A reachable Jenkins instance and a test job name (provided as flow inputs).
  • A Docker-capable worker (the task runner pulls hashicorp/terraform and cytopia/ansible images).

Secrets

  • JENKINS_USERNAME: Jenkins user for Basic Auth.
  • JENKINS_API_TOKEN: Jenkins API token.
  • DISCORD_WEBHOOK_URL: Discord incoming webhook URL.

Quick start

  1. Add the secrets above to your Kestra namespace.
  2. Set the jenkins_url input and provide the jenkins_test_job name.
  3. Replace the stub Terraform (random_pet) and Ansible (localhost ping) content with your real configuration.
  4. Run the flow and watch the chain outcome land in Discord.

How to extend

  • Drop Terraform or Ansible to fit your stack; the chain works with any subset.
  • Add a schedule or webhook trigger to run the pipeline on demand or on a cadence.
  • Gate the Discord notification on the test result by adding an If task between wait_for_jenkins and notify.
  • For foldered Jenkins jobs, adapt the jobName and the lastBuild URI path accordingly.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.