Skip to content

Commit c604db7

Browse files
authored
Added a better example of jenkins with cli (#35)
1 parent ae6f03b commit c604db7

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

jenkins/new-scan-engine/Jenkinsfile-jenkins-plugin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pipeline {
33
image = "docker.io/myawesomecompany/myawesomeimage" + ":$BUILD_NUMBER"
44
registryCredential = "registry-credentials"
55
repository = 'https://github.com/sysdiglabs/secure-inline-scan-examples.git'
6+
api_endpoint = 'https://eu1.app.sysdig.com'
67
myimage = ''
78
}
89
agent any
@@ -21,7 +22,7 @@ pipeline {
2122
}
2223
stage('Scanning Image') {
2324
steps {
24-
sysdigImageScan engineCredentialsId: 'sysdig-secure-api-token', imageName: "docker://" + image, engineURL: 'https://eu1.app.sysdig.com'
25+
sysdigImageScan engineCredentialsId: 'sysdig-secure-api-token', imageName: "docker://" + image, engineURL: api_endpoint
2526
}
2627
}
2728
stage('Deploy Image') {
Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
pipeline {
2-
agent any
32

4-
stages {
5-
stage('Scan image') {
6-
steps {
7-
withCredentials([usernamePassword(credentialsId: 'sysdig-secure-api-credentials', passwordVariable: 'SECURE_API_TOKEN', usernameVariable: '')]) {
3+
parameters {
4+
string(name: 'DOCKER_REPOSITORY', defaultValue: 'sysdigcicd/cronagent', description: 'Name of the image to be built (e.g.: sysdiglabs/dummy-vuln-app)')
5+
string(name: 'GIT_REPOSITORY', defaultValue: 'https://github.com/sysdiglabs/secure-inline-scan-examples.git', description: 'Name of the repository with the Dockerfile to be built (e.g.: https://github.com/sysdiglabs/secure-inline-scan-examples.git)')
6+
string(name: 'SYSDIG_ENDPOINT', defaultValue: 'https://eu1.app.sysdig.com', description: 'The appropriate Sysdig vulnerability scanning endpoint depending on your region, see https://docs.sysdig.com/en/docs/administration/saas-regions-and-ip-ranges (e.g.: https://github.com/sysdiglabs/secure-inline-scan-examples.git)')
7+
}
8+
9+
agent any
10+
stages {
11+
stage('Cloning Git') {
12+
steps {
13+
git branch: 'main', url: "${params.GIT_REPOSITORY}"
14+
}
15+
}
16+
stage('Build Image') {
17+
steps {
18+
sh "docker build -f ./jenkins/new-scan-engine/Dockerfile -t ${DOCKER_REPOSITORY} ./jenkins/new-scan-engine/"
19+
}
20+
}
21+
stage('Scan image') {
22+
steps {
23+
withCredentials([usernamePassword(credentialsId: 'sysdig-secure-api-token', passwordVariable: 'SECURE_API_TOKEN', usernameVariable: '')]) {
24+
sh '''
25+
VERSION=$(curl -L -s https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt)
26+
curl -LO "https://download.sysdig.com/scanning/bin/sysdig-cli-scanner/${VERSION}/linux/amd64/sysdig-cli-scanner"
27+
chmod +x ./sysdig-cli-scanner
28+
./sysdig-cli-scanner --apiurl ${SYSDIG_ENDPOINT} docker://${DOCKER_REPOSITORY}
29+
'''
30+
}
31+
}
32+
}
33+
stage('Push Image') {
34+
35+
steps {
36+
withCredentials([usernamePassword(credentialsId: 'registry-credentials', passwordVariable: 'password', usernameVariable: 'username')]){
837
sh '''
9-
VERSION=$(curl -L -s https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt)
10-
curl -LO "https://download.sysdig.com/scanning/bin/sysdig-cli-scanner/${VERSION}/linux/amd64/sysdig-cli-scanner"
11-
chmod +x ./sysdig-cli-scanner
12-
./sysdig-cli-scanner --apiurl https://secure.sysdig.com mongo-express:0.54.0
38+
docker login -u ${username} -p ${password}
39+
docker push ${DOCKER_REPOSITORY}
1340
'''
14-
}
15-
}
16-
}
41+
} }
42+
}
1743
}
1844
}

jenkins/new-scan-engine/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ There are two different approaches if using Jenkins to scan container images for
99

1010
This [example pipeline](Jenkinsfile-sysdig-cli-scanner) shows how to download and execute the new inline scanner to scan an image.
1111

12-
It requires to configure a Jenkins credential `sysdig-secure-api-credentials` to store the Sysdig Token (as password)
12+
It requires to configure a Jenkins credential `sysdig-secure-api-token` to store the Sysdig Token (as password)
1313

1414
![Screenshot of Jenkins UI](https://github.com/jenkinsci/sysdig-secure-plugin/raw/main/docs/images/SysdigTokenConfiguration.png)
1515

16-
Then the scan is performed by downloading the `sysdig-cli-scanner` tool against the `mongo-express:0.54.0` example image.
16+
Then the scan is performed by downloading the `sysdig-cli-scanner` tool against the example image.
1717

1818
For a more elaborated example, see the [GitHub](../../github/new-scan-engine/README.md) example.
1919

@@ -29,5 +29,6 @@ The [example pipeline](Jenkinsfile-jenkins-plugin) shows how to use it to build
2929

3030
Both approaches require a couple of things:
3131

32-
* A valid Sysdig Secure API token
33-
* Have access to the image storage, either to the local storage where the image was created or to the registry where it is stored.
32+
* A valid Sysdig Secure API token.
33+
* Have access to the image storage, either to the local storage where the image was created or to the registry where it is stored.
34+
* The appropriate Sysdig vulnerability scanning endpoint depending on your region, see [the official documentation](https://docs.sysdig.com/en/docs/administration/saas-regions-and-ip-ranges).

0 commit comments

Comments
 (0)