> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/sast-and-sca/prezero/static-analysis-sast/workflows/jenkins.md).

# Jenkins

This tutorial shows you how to integrate Qwiet AI by Harness into your Jenkins workflow for automated code analysis.

To run Qwiet AI by Harness as part of your Jenkins workflow, you will need to:

1. [Provide your Qwiet account parameters to Jenkins](#provide-your-qwiet-account-parameters-to-jenkins)
2. [Configure the integration with Jenkins using the method of your choice](#integrating-with-jenkins)
3. [Verify your integration](#verify-the-prezero-jenkins-integration)

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

This tutorial assumes that you have:

* [Installed Jenkins](https://jenkins.io/download/)
* [Set up Qwiet AI by Harness](broken://spaces/uPVBkglG6gsk2SsnsKgG/pages/fDfomI4jhzwCNFxmGSLc)

## Provide your Qwiet account parameters to Jenkins <a href="#provide-your-qwiet-account-parameters-to-jenkins" id="provide-your-qwiet-account-parameters-to-jenkins"></a>

First, define a secret containing the Qwiet access token that you can inject into your build (Jenkins needs your access token to communicate successfully with Qwiet):

1. Select your username in the top navigation bar.
2. Select **Credentials** in the left-hand pane.
3. Under **Stores from parent**, select **(global)** located under **Domains**.
4. Click **Global credentials (unrestricted)**.
5. On the left-hand side, click **+Add Credentials**.
6. Under **Kind**, select **Secret text**.
7. Provide your **Qwiet access token** as the **Secret** and set its **ID** to `SHIFTLEFT_ACCESS_TOKEN`. When running in a production environment, we recommend using a CI token as the access token. You can [create your CI token](/sast-and-sca/prezero/integrations/tokens.md) in the Qwiet Dashboard.
8. Click **Create** to save and proceed.

![Adding Jenkins environment variables for Qwiet authentication](/files/LDZBFB1ar8W2IR92YtNm)

## Integrating with Jenkins <a href="#integrating-with-jenkins" id="integrating-with-jenkins"></a>

Once you have provided your Qwiet account parameters to Jenkins, you can proceed with the Qwiet AI by Harness integration in one of two ways:

1. **Configuring a final build step that runs Qwiet AI by Harness**: edit the project's build configuration and add the `sl analyze` command as the last step of the build.
2. **Configuring a post-build task for each Jenkins project you want to be analyzed by Qwiet AI by Harness**: install the [Post Build Task plugin](https://plugins.jenkins.io/postbuild-task) and add the `sl analyze` command as a Post Build Task.

We will be working with the [HelloShiftLeft](https://github.com/ShiftLeftSecurity/helloshiftleft) sample app for the following examples, but you are free to use your own app as well.

### Option 1: Configure a final build step <a href="#option-1-configure-a-final-build-step" id="option-1-configure-a-final-build-step"></a>

The instructions for integration Qwiet AI by Harness with Jenkins as a final build step differ based on whether you are configuring a Freestyle project or a Pipeline.

{% tabs %}
{% tab title="Freestyle Projects" %}
The following steps show you how to configure a Jenkins Freestyle project to build and submit HelloShiftLeft for analysis. (If you would like to submit your application for analysis instead of HelloShiftLeft, you can provide the appropriate links to your repository.)

1. Log in to Jenkins with an administrative user account.
2. Choose your Jenkins project. You can create a new Freestyle project, or you can reconfigure an existing Freestyle project.
3. Click **Configure** on the left. Under **General**, check the **GitHub project** box and provide your **Project url** (e.g., `https://github.com/ShiftLeftSecurity/HelloShiftLeft)`.
4. Under **Source Code Management**, select **Git**. This opens up the **Repositories** area. Provide the URL you provided in step 3 as your **Repository URL**. If you need to provide the credentials to access a private repo, do so now as well.
5. Under **Build Triggers**, select **Poll SCM**.
6. Under **Build Environment**, select **Use secret text(s) or file(s)**. When **Bindings** appears, click **Add** and select **Secret Text**. Finally, under **Credentials**, select **Specific credentials** and make sure that **SHIFTLEFT\_ACCESS\_TOKEN** is displayed.
7. Under **Build**, click **Add build step**, and in the drop-down that appears, select **Invoke top-level Maven targets** since we are using Maven to build HelloShiftLeft. You will be asked to provide your **Goals**; enter `clean package`.
8. Click **Add build step** again, and in the drop-down that appears, select **Execute shell**. Provide the following **Command**:

```
#!/bin/bash
/usr/local/bin/sl analyze --app HelloShiftLeft --java target/hello-shiftleft-0.0.1.jar
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

Click **Save**. At this point, you are ready to build and test your project.
{% endtab %}

{% tab title="Pipelines" %}
To have Jenkins run the `sl analyze` shell command as a final build step in a Jenkins Pipeline project, you will need to add the following to your Jenkinsfile:

```
stage('SLAnalyze') {
    dir("<path_to_your_project_package>") {
        sh '/usr/local/bin/sl analyze --app HelloShiftLeft --java target/hello-shiftleft-0.0.1.jar'
    }
}
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)
{% endtab %}
{% endtabs %}

### Option 2: Configure a post-build task <a href="#option-2-configure-a-post-build-task" id="option-2-configure-a-post-build-task"></a>

You can configure a post-build task for each target project that submits your code to Qwiet for analysis.

To begin, [install](https://jenkins.io/doc/book/managing/plugins/#installing-a-plugin) the [Post Build Task plugin](https://plugins.jenkins.io/postbuild-task):

1. Log in to the Jenkins Dashboard and go to **Manage Jenkins** > **Manage Plugins**. Select the **Available** tab on the Plugin Manager screen.
2. In the **Filter**, enter "Post Build Task". Check the **Install** box next to the plugin in the results.
3. At the bottom of the page, choose **Install without restart**.

You will be redirected to a progress page that shows the installation status. After you've installed the plugin, click **Go back to the top page**. You can check for installed plugins by going to **Manage Jenkins** > **Manage Plugins**, then clicking **Installed**.

#### Adding a post-build task <a href="#adding-a-post-build-task" id="adding-a-post-build-task"></a>

Once you've installed the Post Build Task plugin, you can add a post-build action to run Qwiet AI by Harness:

1. Choose your Jenkins project. You can create a new Freestyle project, or you can reconfigure an existing Freestyle project. (If you would like to submit your application for analysis instead of HelloShiftLeft, you can provide the appropriate links to your repository.)
2. Under **General**, provide a link to your **GitHub project**. If you're using HelloShiftLeft, this will be `https://github.com/shiftLeftSecurity/helloshiftleft/`.
3. Under **Source Code Management**, select **Git**. This opens up the **Repositories** area. Provide the `https://github.com/shiftLeftSecurity/helloshiftleft/` as your **Repository URL**.
4. Under **Build Triggers**, select **Poll SCM**.
5. Under **Build Environment**, select **Use secret text(s) or file(s)**. When **Bindings** appears, click **Add** and select **Secret Text**. Finally, under **Credentials**, select **Specific credentials** and make sure that **SHIFTLEFT\_ACCESS\_TOKEN** is displayed.
6. Under **Build**, click **Add build step**, and in the drop-down that appears, select **Invoke top-level Maven targets** since we are using Maven to build HelloShiftLeft. You will be asked to provide your **Goals**; enter `clean package`.
7. Under **Post-build actions**, click **Add post-build action**, and in the drop-down menu that appears, select **Post build task**. In the configuration area that appears, provide the following as your Script:

```
#!/bin/bash
mvn clean package
/usr/local/bin/sl analyze --app HelloShiftLeft --java target/hello-shiftleft-0.0.1.jar
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

Click **Save**. At this point, you are ready to build and test your project.

## Verify the Qwiet AI by Harness-Jenkins integration <a href="#verify-the-qwiet-ai-by-harness-jenkins-integration" id="verify-the-qwiet-ai-by-harness-jenkins-integration"></a>

1. Log in to Jenkins, and choose your Jenkins project.
2. Using the left-hand navigation bar, click **Build Now**. You'll see the build progress in the **Build History** box located beneath the navigation bar.
3. When the build is complete, select the build, and using the left-hand navigation bar, select **Console Output**.
4. Check that you see the following output below that indicates that Qwiet was able to analyze your code successfully:

```
... Done. Submitted for analysis
Wait for 5-10 minutes and load the following URL in your browser:
https://app.shiftleft.io/findingsSummary/HelloShiftLeft?apps=HelloShiftLeft&isApp=1
POST BUILD TASK : SUCCESS
END OF POST BUILD TASK : 0
Finished: SUCCESS
```

![](/files/DfHDmRpYn5HJOmhRtTva) ![](/files/P5vj8JOtHNJWVEvAqKym)

You can click the provided URL in the output to go to the Qwiet Dashboard and view your results (you will be asked to log in if you haven't already done so).
