# Jenkins Pipelines

Zirkul Jobs can be executed from Jenkins Pipelines simply by making webhook calls, however you have to make sure the API Key is protected and avoid hardcoding any secret in your pipeline scripts.

Let's start by storing the Zirkul API Key in Jenkins Credentials manager:

<figure><img src="https://3824814822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2TrvRPLIHQjOEfOcBEbb%2Fuploads%2F3fU0rc805GrmX2k5yr6C%2Fimage.png?alt=media&#x26;token=9ffeb2ad-dc02-405f-878e-b955a3c958ab" alt=""><figcaption></figcaption></figure>

Add a new credential scoped to the project folder:

<figure><img src="https://3824814822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2TrvRPLIHQjOEfOcBEbb%2Fuploads%2FVrRefID062z72mNRm7Bz%2Fimage.png?alt=media&#x26;token=b507585b-ab57-41b4-9c7d-acb1db98e82e" alt=""><figcaption></figcaption></figure>

The kind of secret is "Secret text", in the secret section you can paste the API Key value and use the ID zirkul\_apikey (for convenience in this guide):

<figure><img src="https://3824814822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2TrvRPLIHQjOEfOcBEbb%2Fuploads%2FIMK1i4nbm2Rb2ZM5ZqCD%2Fimage.png?alt=media&#x26;token=64060177-d32c-4d63-9c6e-8efa0acbaa76" alt=""><figcaption></figcaption></figure>

You can then use the secret within the pipeline script in the following way:

<figure><img src="https://3824814822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2TrvRPLIHQjOEfOcBEbb%2Fuploads%2FA5JsZIB8owFk00PpXyqF%2Fimage.png?alt=media&#x26;token=00b597fb-3bde-43ab-8392-0839c3eaa8cc" alt=""><figcaption></figcaption></figure>

Here's the pipeline script:

```yaml
pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                withCredentials([string(credentialsId: 'zirkul_apikey', variable: 'zirkul_apikey')]) {
                    sh 'curl -H "X-API-KEY: $zirkul_apikey" https://app.zirkul.com/api/webhook/f3f75cca-da48-4720-be53-8c0396ca041e'
                }
            }
        }
    }
}
```

Note you may need to update the webhook id with the [URL provided by Zirkul for your Job](https://docs.zirkul.com/running-jobs#webhook-calls).

Once you run the pipeline, the console output should look like this:

<figure><img src="https://3824814822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2TrvRPLIHQjOEfOcBEbb%2Fuploads%2FOTg3mBWGm3eXST4MIgaJ%2Fimage.png?alt=media&#x26;token=c4d2c8d9-df09-49ca-80d8-963929904f31" alt=""><figcaption></figcaption></figure>

Note:

* The API Key is protected and is not included in the logs
* The webhook call returned the message "Success"
