Jenkins is an open source software used to automate the software development process. Jenkins main advantage is his flexibility and ability to integrate with the various tools and technologies commonly used in software development.
In this section this guide will be described using Jenkins:
Without Jenkins file
First step, copy all Jenkins syntactic code below.
stage('I3GIS_SCAN') {
steps {
script {
echo "Scanning project golang-sca with i3gis..."
final String url = """--location -g --request POST 'https://jenkins-svc-dev.i3gis.id/scan' --header 'Content-Type: application/json' --header 'Authorization: Bearer mG9BsdJqG9rbH5Pi/CBF1edE+pC5LAkeq95TKXW8Lv/4/eZqrnMXEN1BGlUEfnj7FDLX4TjhkFKRmC8rqG6Gbuvy/Iq+h8OKEIbt7mncDfz/+GGh7m/GoW5l9sCp0LPqhuBDFyxlHPEzg6m0WheDCg==' -d '{"project_id":23}'"""
final def (String response, int code) = sh(script: "set +x; curl -s -w '\n%{response_code}' $url", returnStdout: true).trim().tokenize("
")
echo "HTTP response status code: $code"
if (code != 200) {
echo "Response: " + response
error("Build failed because scan not success...")
} else {
echo "Scan project golang-sca with i3gis..."
}
echo "Scan project golang-sca with i3gis is starting..."
}
}
}
stage('I3GIS_SCAN_STATUS') {
steps {
script {
echo "Get scan status..."
final Boolean status_running = true
while(status_running) {
sleep(time: 5, unit: "SECONDS")
echo "Scan still running..."
final String url1 = """--location -g --request GET 'https://jenkins-svc-dev.i3gis.id/scan/23' --header 'Content-Type: application/json' --header 'Authorization: Bearer mG9BsdJqG9rbH5Pi/CBF1edE+pC5LAkeq95TKXW8Lv/4/eZqrnMXEN1BGlUEfnj7FDLX4TjhkFKRmC8rqG6Gbuvy/Iq+h8OKEIbt7mncDfz/+GGh7m/GoW5l9sCp0LPqhuBDFyxlHPEzg6m0WheDCg=='"""
final def (String response1, int code1) = sh(script: "set +x; curl -s -w '\n%{response_code}' $url1", returnStdout: true).trim().tokenize("
")
echo "HTTP response status code: $code1"
if (code1 != 200 && code1 != 404) {
echo "Response: " + response1
error("Scan failed...")
}
if(code1 == 404) break
}
echo "Scan finished..."
}
}
}
The second step is on the Pipeline at Jenkins click the Configure menu.
On the Configure menu page, move to the Pipeline Setting Section then in Column Definition to Pipeline Script and paste the syntax code you copied into the Column Script.
With Jenkinsfile
For the first step copy Jenkins syntactic code below.
stage('I3GIS_SCAN') {
steps {
script {
echo "Scanning project golang-sca with i3gis..."
final String url = """--location -g --request POST 'https://jenkins-svc-dev.i3gis.id/scan' --header 'Content-Type: application/json' --header 'Authorization: Bearer mG9BsdJqG9rbH5Pi/CBF1edE+pC5LAkeq95TKXW8Lv/4/eZqrnMXEN1BGlUEfnj7FDLX4TjhkFKRmC8rqG6Gbuvy/Iq+h8OKEIbt7mncDfz/+GGh7m/GoW5l9sCp0LPqhuBDFyxlHPEzg6m0WheDCg==' -d '{"project_id":23}'"""
final def (String response, int code) = sh(script: "set +x; curl -s -w '\n%{response_code}' $url", returnStdout: true).trim().tokenize("
")
echo "HTTP response status code: $code"
if (code != 200) {
echo "Response: " + response
error("Build failed because scan not success...")
} else {
echo "Scan project golang-sca with i3gis..."
}
echo "Scan project golang-sca with i3gis is starting..."
}
}
}
stage('I3GIS_SCAN_STATUS') {
steps {
script {
echo "Get scan status..."
final Boolean status_running = true
while(status_running) {
sleep(time: 5, unit: "SECONDS")
echo "Scan still running..."
final String url1 = """--location -g --request GET 'https://jenkins-svc-dev.i3gis.id/scan/23' --header 'Content-Type: application/json' --header 'Authorization: Bearer mG9BsdJqG9rbH5Pi/CBF1edE+pC5LAkeq95TKXW8Lv/4/eZqrnMXEN1BGlUEfnj7FDLX4TjhkFKRmC8rqG6Gbuvy/Iq+h8OKEIbt7mncDfz/+GGh7m/GoW5l9sCp0LPqhuBDFyxlHPEzg6m0WheDCg=='"""
final def (String response1, int code1) = sh(script: "set +x; curl -s -w '\n%{response_code}' $url1", returnStdout: true).trim().tokenize("
")
echo "HTTP response status code: $code1"
if (code1 != 200 && code1 != 404) {
echo "Response: " + response1
error("Scan failed...")
}
if(code1 == 404) break
}
echo "Scan finished..."
}
}
}
Then go into the Jenkins file you have and paste the copied syntactic code into the stage bracket as below.
CI/CD: Bamboo
Bamboo is an open source software that is used to automate software development processes. Make sure you've created a project and linked it to your repository, and created a job in the plan on the Bamboo platform.
This section of the guide will be described using Bamboo:
Click the Configure Plan menu.
On the Tasks tab and click the Add Task button to add a new task.
In the search column type script.
Copy the following syntax code.
echo "Scanning project golang-sca with i3gis..."
scanResponse=$(curl --write-out '%{http_code}' --request POST -sL \
--url 'https://jenkins-svc-dev.i3gis.id/scan'\
--header 'Content-Type: application/json'\
--header 'Authorization: Bearer rtt2Ihba2AJVQjhmgonuAdjcD+3GIeBK5Q8SgOGt38TPG3YrACeCA7yGJCSX8fWArIlv62Zlli75Ay3UToFa0K4wgJHTTCP3KvlFS8Q+Te90eQkcOUyo7qGGSgSbTiQ8OIP5UEuwshZpSFnyd5ijRg=='\
--data '{"project_id":23}')
scanCode=$(echo $scanResponse | grep -o ...$)
echo "HTTP response status code: $scanCode"
if [ $scanCode = '200' ]; then
echo "Scan project golang-sca with i3gis..."
else
echo "Response: $scanResponse"
echo "Build failed because scan not success..."
exit 1
fi
echo "Scan project golang-sca with i3gis is starting..."
echo "Get scan status..."
status_running=true
while [ "$status_running" = true ]; do
sleep 5
echo "Scan still running..."
checkResponse=$(curl --write-out '%{http_code}' --request GET -sL \
--url 'https://jenkins-svc-dev.i3gis.id/scan/3'\
--header 'Content-Type: application/json'\
--header 'Authorization: Bearer rtt2Ihba2AJVQjhmgonuAdjcD+3GIeBK5Q8SgOGt38TPG3YrACeCA7yGJCSX8fWArIlv62Zlli75Ay3UToFa0K4wgJHTTCP3KvlFS8Q+Te90eQkcOUyo7qGGSgSbTiQ8OIP5UEuwshZpSFnyd5ijRg==')
checkCode=$(echo $checkResponse | grep -o ...$)
echo "HTTP response status code: $checkCode"
if [ $checkCode != '200' ] && [ $checkCode != '404' ]; then
echo "Response: $checkResponse"
echo "Scan failed..."
exit 1
fi
if [ $checkCode = '404' ]; then
echo "Scan finished..."
status_running=false
fi
done
Paste the syntax code you copied previously in the Script Body column. Click the Save button to save the changes.
CI/CD: Gitlab
Gitlab is an open source software tool used to automate software development processes.
This section of the guide will explain integrating Gitlab:
The first step is to make sure you have Gitlab installed on your computer. For more details you can visit the Gitlab website page.
On the GitLab repository page click the Settings menu. and select the CI/CD menu.
On the Specific runners page there is a Token Registration, copy the syntax below.
If successful run the command. In your repository folder create a gitlab-ci.yaml file in your repository. Copy the syntax code below and paste it into the gile gitlab-ci.yml that was created and push it to the gitlab repository.
stages:
- test
i3gis-job:
stage: test
script:
- echo "Scanning project project-public with i3gis..."
- 'scanResponse=$(curl --write-out ''%{http_code}'' --request POST -sL --url ''https://api-dev.ast.cloudeka.id/scan-svc/scan'' --header ''Content-Type: application/json'' --header ''Authorization: Bearer fVtuP9ZXxKFEMYP0pPJqwEoLuBLxJ47pD0CUj5lpi+Fu6HUJuTokwq3X7amdZYSso2hpGUmE3YA7kx8WiGKYn59THbBDPSNJPs/NgTXTCnxAGlTt0o6pcoucLfMcaYkVy/glEC6KmTU2eqP/utDWM80DEapfZXTKdqu6p30oP14='' --data ''{"project_id":67}'')'
- scanCode=$(echo $scanResponse | grep -o ...$)
- 'echo "HTTP response status code: $scanCode"'
- if [ $scanCode = "200" ]; then
- echo "Scan project project-public with i3gis..."
- else
- 'echo "Response: $scanResponse"'
- echo "Build failed because scan not success..."
- exit 1
- fi
- echo "Scan project project-public with i3gis is starting..."
i3gis-status-job:
stage: test
script:
- echo "Get scan status..."
- status_running=true
- while [ "$status_running" = true ]; do
- sleep 5
- echo "Scan still running..."
- 'checkResponse=$(curl --write-out ''%{http_code}'' --request GET -sL --url ''https://api-dev.ast.cloudeka.id/scan-svc/scan/67'' --header ''Content-Type: application/json'' --header ''Authorization: Bearer fVtuP9ZXxKFEMYP0pPJqwEoLuBLxJ47pD0CUj5lpi+Fu6HUJuTokwq3X7amdZYSso2hpGUmE3YA7kx8WiGKYn59THbBDPSNJPs/NgTXTCnxAGlTt0o6pcoucLfMcaYkVy/glEC6KmTU2eqP/utDWM80DEapfZXTKdqu6p30oP14='')'
- checkCode=$(echo $checkResponse | grep -o ...$)
- 'echo "HTTP response status code: $checkCode"'
- if [ $checkCode != "200" ] && [ $checkCode != "404" ]; then
- 'echo "Response: $checkResponse"'
- echo "Scan failed..."
- exit 1
- fi
- if [ $checkCode = "404" ]; then
- echo "Scan finished..."
- status_running=false
- fi
- done
After a successful commit and push of the gitlab-ci.yml file. Describe the syntax for the gitlab-ci.yml file by running the command below.
gitlab-runner exec shell i3gis-job
gitlab-runner exec shell i3gis-status-job
CI/CD: Github
Make sure you already have a repository on github.
This guide will explain how to integrate Github:
On your Github repository page select the Actions tab and hit the New Workflow button.
Click Set up a workflow yourself, you will be redirected to code editing where you can define your own workflow.
This step is based on the assumption that you don't have a workflow yet but if you have multiple workflows you can skip this step and move to the next step. Specify the initials in the workflow by filling in the line "name" and the line "on" as in the Image below.
Copy all github-action scripts below.
jobs:
i3gis-job:
runs-on: ubuntu-latest
steps:
- name: Scan project with i3gis
run: |
echo "Scanning project project-public with i3gis..."
scanResponse=$(curl --write-out '%{http_code}' --request POST -sL --url 'https://api-dev.ast.cloudeka.id/scan-svc/scan' --header 'Content-Type: application/json' --header 'Authorization: Bearer D2/kx5A1oobZzhloPGyjyr/4ZDPNVEmABVjxB+4PmGVfH0XdmuFB/oSwI0YeTn1E9loNDPPdwIvTfqo0kllIKMWOfIH1Ig3F8RQBMVxk6b2jZHMmCN3k1yjfENapnr/0la65m61B3yawrHH2Rc7ZzSs0jCdKfq5TzSyqh9oZuqE=' --data '{"project_id":67}')
scanCode=$(echo $scanResponse | grep -o ...$)
echo "HTTP response status code: $scanCode"
if [ $scanCode = "200" ]; then
echo "Scan project project-public with i3gis..."
else
echo "Response: $scanResponse"
echo "Build failed because scan was not successful..."
exit 1
fi
echo "Scan project project-public with i3gis is starting..."
i3gis-status-job:
runs-on: ubuntu-latest
steps:
- name: Get scan status
run: |
echo "Get scan status..."
status_running=true
while [ "$status_running" = true ]; do
sleep 5
echo "Scan still running..."
checkResponse=$(curl --write-out ''%{http_code}'' --request GET -sL --url 'https://api-dev.ast.cloudeka.id/scan-svc/scan/67' --header 'Content-Type: application/json' --header 'Authorization: Bearer D2/kx5A1oobZzhloPGyjyr/4ZDPNVEmABVjxB+4PmGVfH0XdmuFB/oSwI0YeTn1E9loNDPPdwIvTfqo0kllIKMWOfIH1Ig3F8RQBMVxk6b2jZHMmCN3k1yjfENapnr/0la65m61B3yawrHH2Rc7ZzSs0jCdKfq5TzSyqh9oZuqE=')
checkCode=$(echo $checkResponse | grep -o ...$)
echo "HTTP response status code: $checkCode"
if [ $checkCode != "200" ] && [ $checkCode != "404" ]; then
echo "Response: $checkResponse"
echo "Scan failed..."
exit 1
fi
if [ $checkCode = "404" ]; then
echo "Scan finished..."
status_running=false
fi
done
Paste the github-action syntax below. Click Preview to make sure everything looks correct and hit the Commit Changes button.
After committing the workflow file, you will be redirected to the Actions tab. You will see your workflow listed according to the name you provided. Github will run automatically according to predefined rules.
Notification: SMTP
SMTP (Simple Mail Transfer Protocol) is a standard protocol used for sending e-mail over computer networks. This protocol allows the sending of email messages from the sender to the recipient's email server. SMPT acts as a reliable messaging system for transferring e-mails over the internet.
Here are the steps to add SMTP:
On the Cloudeka portal service page, select Integration on Deka AST.
On the Integration page select SMTP and press the Add SMTP button.
The Create SMTP Server window appears. Fill in the Host Server Column, SMTP Port, Email Tester, and Password.
Notification: Telegram
This application is designed to provide messaging services that are fast, secure and can be accessed from various devices. Telegram has one feature, namely automatic bots that can provide information, perform certain tasks and send automatic updates to users.
This guide will explain how to create bots on Telegram:
Create a bot on Telegram according to the operating system you are using.
On Iphone start with a new message by tapping the icon at the top right corner in the chat then select New Channel.
On Android, start by tapping the pencil icon in the chat list and then selecting New Channel.
On Windows start by clicking Menu to open the sidebar then selecting New Channel.
Create bots to send notifications on BotFather, and get tokens for API requests. On bot creation BotFather will ask for your name and username and then generate an authentication token for the new bott. The username is the short name that will be linked to t.me. Username must use:
a. 5-32 characters long.
b.It doesn't matter if you use lowercase or uppercase.
c.Use only letters, numbers, and underscore characters.
d.Bot usernames must end with the word “bot”.
Make sure you copy the token and keep it safe so that it can't be used by anyone to control your bot.
Add a bot to the newly created Channel and make sure the bot is an Administrator.
Activate the channel by typing “activate i3gis notification”
On the Cloudeka portal service page, on the Integration menu, select Telegram. Enter the API token you got and press the Confirm button.
The notification "Create telegram bot successfully" appears and in the List BOT & Channel section the bot that you created in Telegram appears.