Merge pull request #19004 from dvdksn/fix-jenkins-credentials-ex

scout: fix jenkins ci example
This commit is contained in:
David Karlsson 2024-01-03 20:50:04 +01:00 committed by GitHub
commit 6358a48cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 13 deletions

View File

@ -5,23 +5,35 @@ title: Integrate Docker Scout with Jenkins
--- ---
You can add the following stage and steps definition to a `Jenkinsfile` to run You can add the following stage and steps definition to a `Jenkinsfile` to run
Docker Scout as part of a Jenkins pipeline. The pipeline needs two secrets Docker Scout as part of a Jenkins pipeline. The pipeline needs a `DOCKER_HUB`
defined to authenticate with Docker Hub: `DOCKER_HUB_USER` and `DOCKER_HUB_PAT` credential containing the username and password for authenticating to Docker
It also needs an environment variable defined for the image and tag. Hub. It also needs an environment variable defined for the image and tag.
```groovy ```groovy
pipeline {
stage('Analyze image') { agent {
// Agent details
}
environment {
DOCKER_HUB = credentials('jenkins-docker-hub-credentials')
IMAGE_TAG = 'myorg/scout-demo-service:latest'
}
stages {
stage('Analyze image') {
steps { steps {
// Install Docker Scout // Install Docker Scout
sh 'curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- -b /usr/local/bin' sh 'curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- -b /usr/local/bin'
// Log into Docker Hub // Log into Docker Hub
sh 'echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USER --password-stdin' sh 'echo $DOCKER_HUB_PSW | docker login -u $DOCKER_HUB_USR --password-stdin'
// Analyze and fail on critical or high vulnerabilities // Analyze and fail on critical or high vulnerabilities
sh 'docker-scout cves $IMAGE_TAG --exit-code --only-severity critical,high' sh 'docker-scout cves $IMAGE_TAG --exit-code --only-severity critical,high'
} }
}
}
} }
``` ```