# Jenkins

![jenkins-logo.png](https://assets.relyanceuat.xyz/images/docs/6612363059085/6611781659149.png)
Jenkins is an extensible automation server that provides Continuous Integration and Continuous Delivery (CI/CD) in a Dev-ops environment.

This how-to will provide a basic understanding of how add the Relyance Source Code inspector (SCI) into a typical build job.

### Prerequisites:

1. Jenkins should be configured and setup prior to going through this setup. Depending on the version of Jenkins, it may look different from one install to the next. These steps should act as a basic guide for most installations.
2. Docker needs to be available in the Jenkins environment.
3. A source code repository needs to be available.
4. The `relyance.yaml` file needs to be in the source code root directory.
5. Grab the command line code from **Step 2** of the Relyance Source Code Integration settings from *your* Relyance instance.

![Step-2.png](https://assets.relyanceuat.xyz/images/docs/6612363059085/15211046663949.png)

See more info about the SCI commands **[here](#h_01GYWE2TT304X30S45KJATK7T5)**.

### Steps:

1. Login to your Jenkins environment in a browser.
2. On your dashboard, you can either pick one of the jobs listed or you create a new job.

 i. If you are editing an existing job, try to add the SCI step as close to the end as possible.
 This should be after the source code has been fetched and/or built.

 ii. If you are creating a new job, create the new job and choose a Freestyle project.

 Make sure you fetch and/or build your **Source Code** repository using Jenkins build steps.
3. Ensure your source code repository has the preconfigured `relyance.yaml` file in the root path of your source code. Also ensure you choose the correct branch the `relyance.yaml` file is in.
4. Under the **Build** section, click on **Add build step** and select **Execute shell**.
5. Paste the **Step 2** command into the Jenkins command box. Ensure the docker run command path '**pwd**' is correct in this command for this CI/CD.

If not, replace it with the correct **full** path in your Jenkins environment. Try running each SCI command in your Jenkins shell first.
6. If you wish to schedule this job, you would enable the **Build periodically** checkbox in the **Build Triggers** section and put in a schedule (in cron format).  Click the help icon beside **Schedule** to see the cron format Jenkins uses.
H ('hash') is used to schedule a time when the system performance won't be impacted by other jobs.
7. Click **Save**.
8. This will drop you back into the Build job.
9. Click **Build Now**.
10. The build will start to run. You should be able to click on the build job number and see the status. This may take awhile as the Relyance SCI image file is downloaded and loaded into docker.
11. Go to the **Console Output** in the build job to see the progression.
12. Once complete, adjust the build configuration if there are any errors.
13. If there are no errors, you should start to see SCI results in your Relyance tenant.

![Jenkins-2.png](https://assets.relyanceuat.xyz/images/docs/6612363059085/9370422560141.png)

### Appendix:

Source Code Integration **Step 2** info:

**Example Step 2 Command**

| 1 | docker pull  gcr.io/relyance-ext/compliance_inspector:release  && \ |
| --- | --- |
| 2 | docker run --rm -v `pwd`:/repo --env 'API_KEY= example :abcdefg0123456789abcdefg0123456789abcdefg'  gcr.io/relyance-ext/compliance_inspector:release |

1. This command pulls the latest version of the Relyance Source Code Inspector.
2. This command initiates the Relyance Source Code Inspector within a local Docker container, establishing a shared folder and providing the necessary tenant API credentials.
