Skip to main content

Jenkins integration

Connect your Jenkins so Leanmote keeps its builds and finds the ones that deployed to production.

Connect Jenkins to Leanmote so it keeps every build of your Jenkins and finds the ones that deployed to production. Leanmote never runs a job or changes anything in your Jenkins.


​

Two ways to connect


​

You choose how, and you can use both at the same time.


​

Way to connect

Webhook

API token

What you do

Add a step to your deploy pipelines.

Create a Jenkins user for Leanmote and paste its token.

What arrives

Each build, when it finishes, from the moment you add the step.

The builds of the last year, and then a daily read.

What Leanmote needs

Nothing: Leanmote never reaches your Jenkins. Your pipelines send each build.

To reach your Jenkins over https. If a firewall protects it, allow Leanmote's address, 100.27.182.179.


​

A firewall does not decide it on its own: you can allow Leanmote's address and use the API token, or use the webhook even if Leanmote could reach your Jenkins.


​

Connect with the webhook


​

  1. In Leanmote, go to Integrations, open Jenkins, choose Webhook and click Generate the secret. Copy it: Leanmote shows it only once.

  2. In Jenkins, go to Manage Jenkins › Credentials and click Add Credentials. In Kind choose Secret text, paste the secret in Secret, write leanmote-webhook-secret in ID, and save.

  3. In Manage Jenkins › System, section Jenkins Location, check that Jenkins URL holds the address you open Jenkins with. Without it, builds arrive without their link, and the same build could be counted twice when you also use the API token.

  4. Back in Leanmote, choose how you use Jenkins, copy the snippet and add it to your deploy pipelines. The snippet already carries your organization's id.


​

How you use Jenkins

Where the snippet goes

Declarative pipeline

In the post block of the pipeline that deploys.

Deploy as a stage of a pipeline

In the post block of the deploy stage, inside the pipeline that also builds and tests. A build counts when that stage succeeded, even if a later stage fails.

Scripted pipeline

In the finally of the node that deploys.

Shared library

As vars/leanmoteReport.groovy in your shared library; then one line in each pipeline.

Freestyle job

As the last Execute shell step of the deploy job. It reports successful deploys only.


​

The snippet never fails a build: if Leanmote cannot be reached, the build continues as it would without it.


​

If the Jenkinsfile lives in another repository than the service it deploys (a repository of pipelines or of deploy configs), set LEANMOTE_REPO_URL to the service's repository, and LEANMOTE_COMMIT and LEANMOTE_BRANCH if the pipeline knows them. Otherwise the build is tied to the repository the Jenkinsfile came from.


​

To change the secret, click Generate a new secret. The old one stops working at once, so update the credential in Jenkins right away.


​

Connect with an API token


​

  1. In Jenkins, go to Manage Jenkins › Users and create a user just for Leanmote, with the Overall/Read and Job/Read permissions. A Jenkins API token can do whatever its user can, so give this user nothing else: Leanmote only reads.

  2. Signed in as that user, click your name, then Security › API Token › Add new token. Copy it: Jenkins shows it only once.

  3. If a firewall protects your Jenkins, allow Leanmote's address, 100.27.182.179. Leanmote connects only over https, to a public address with a valid certificate.

  4. In Leanmote, go to Integrations, open Jenkins, choose API token, paste the URL, the user and the token, and click Connect. Leanmote checks them with Jenkins before saving anything, then reads the builds of the last year and, from then on, every day.


​

To read the stage of each build (when you deploy from a stage), Leanmote needs the Pipeline Graph View plugin in Jenkins, or Pipeline: Stage View.


​

Which builds count as deployments


​

A deployment is a successful build of a deploy job to production. By default:


​

  • Deploy jobs are the ones whose full name, folders included, contains deploy.

  • Production is a build whose environment, or job name when it has none, says prod, prd, production or live.

  • The environment comes from the build parameter ENV, ENVIRONMENT, DEPLOY_ENV, TARGET_ENV or DEPLOY_ENVIRONMENT.


​

To change them, open Integrations › Jenkins › Which builds count as deployments. Each field is a regular expression, not case-sensitive; empty uses the default. If you deploy from a stage of a pipeline, write that stage's name in Deploy stage: a build then counts when that stage succeeded.


​

Each build is tied to its repository in Leanmote when the repository it names is one your organization connected (GitHub, GitLab, Bitbucket or Azure DevOps).


​

Add Jenkins to DORA


​

Connecting Jenkins does not change your DORA metrics on its own. To count its deployments, the organization owner turns on Jenkins deployments in Settings → Organization Settings → Tabs → Metrics, under Where deployments are counted.


​

  • They are added to your GitLab or Bitbucket deployments, so choose one of them as the source first. With merged pull requests, GitHub or Datadog as the source, the switch is shown but cannot be turned on.

  • Each Jenkins deployment counts once, as Jenkins'. A failure follows the same rule as GitLab's and Bitbucket's: a deployment a later one had to undo, or fix with a hotfix.

  • With the webhook, the builds count from the moment you added the step to your pipelines. With the API token, the builds your Jenkins still keeps count too, up to a year back: Jenkins discards old builds as each job is set to.

  • Lead Time for Changes does not change.


​

In the DORA tab, the hover of Deployment Frequency, Change Failure Rate and Time to Restore names Jenkins and the last build received. In their Show Details, the Tool column says which tool deployed each one, and a Jenkins deployment links to its build.


​

Turning it off stops counting them. The builds are kept.


​

What the Jenkins window shows


​

Once connected, the Jenkins window says how it is connected, the last build received and how many arrived in the last 30 days. It also warns about what to fix:


​

  • Builds without a URL: fill in the Jenkins URL in Jenkins.

  • Builds from repositories your organization did not connect: connect them in their tool and Leanmote assigns those builds.

  • No stages: install the Pipeline Graph View plugin.

  • Jenkins stopped accepting the token: create a new token and connect again.

  • Leanmote could not read the saved token: connect again with a new token.

  • Builds that did not arrive: a build arrived signed with a secret that is not the current one, so it was not saved. Check the leanmote-webhook-secret credential in Jenkins, or generate a new secret. This warning only shows for builds of your own Jenkins.


​

Security


​

  • The organization id in the snippet is not a secret. It only tells Leanmote which secret checks the report: without your secret, nobody can send builds to your organization, and a report with another organization's id is rejected without telling anything about it.

  • The secret and the API token are stored encrypted, and Leanmote never shows them again.


​

Disconnect


​

Disconnect Jenkins stops receiving and reading your builds, deletes the secret and the token, and stops adding its deployments to DORA. The builds already received are kept, so if you connect again the history continues. If both ways are connected, you can also stop using just one of them.


​

Connection details


​

Detail

Value

Connection type

Webhook signed with a secret Leanmote generates, or a Jenkins user's API token. No OAuth.

Who connects in Jenkins

Someone who can add credentials and edit the deploy pipelines (webhook), or create users and give them permissions (API token): usually a Jenkins admin.

Who can connect in Leanmote

Owner or Manager.

Write access

None. The webhook gives Leanmote no access to Jenkins. With the API token, Leanmote only reads, and the token can do only what its user can: give that user Overall/Read and Job/Read and nothing else.

Did this answer your question?