Setting up Bandit with Jenkins & Git for Python SAST
Bandit is a source code review tool for Python codes.
This article is about automating the process of code review of Python codes. We will be using Jenkins for governing the automation process, & code to be tested is on Github. So, we are going to automate the process of pulling Python code from Github, running Bandit scan on the code based on local machine and saving the output in a text file, in one click.
Step 1:
Make sure system satisfy below mentioned requirements:
Python27 installed
pip configured
Jenkins servers installed & configured
Step 2:
Creating up Jenkins build for code review:
In the home page, click New Item
Enter item name as Bandit or whatever you wish.
Follow Screenshot:
In Project url field insert the URL of Github project
https://github.com/Test/WebGoat/
Repository URL would end with https://github.com/Test/WebGoat/WebGoat.git
Steps to add git credentials is provided below:
Note: To add credentials follow below screenshot:
Select Username with password in Global credentials
Add credentials with ID & Description
Highlighted portion shows credentials successfully added
Step 3:
In order to execute Bandit, select Windows PowerShell for Windows.
Note: For Linux systems select Execute shell
Insert below command, in either shell.
Now, scroll down to the bottom & click Save & Apply
Step 4:
Initiate one click Jenkins build
After build is successful, check for Console Output.
Browse through the console logs.
Step 5:
Below is the output of scan and my code is fine with no vulnerability
References: