2022-02-11 16:47:10 +00:00
|
|
|
// Common container builder by ZeroDownTime
|
|
|
|
|
2022-02-14 12:15:52 +00:00
|
|
|
def call(Map config=[:]) {
|
2022-02-11 17:13:04 +00:00
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
node {
|
|
|
|
label 'podman-aws-trivy'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Prepare') {
|
|
|
|
steps {
|
2023-04-03 09:28:13 +00:00
|
|
|
// pull tags
|
|
|
|
withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) {
|
|
|
|
sh 'git fetch -q --tags ${GIT_URL}'
|
|
|
|
}
|
|
|
|
sh 'make prepare || true'
|
2022-02-11 17:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-11 16:47:10 +00:00
|
|
|
|
2022-02-11 17:13:04 +00:00
|
|
|
// Build using rootless podman
|
|
|
|
stage('Build') {
|
|
|
|
steps {
|
|
|
|
sh 'make build'
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 16:47:10 +00:00
|
|
|
|
2022-02-11 17:13:04 +00:00
|
|
|
stage('Test') {
|
|
|
|
steps {
|
|
|
|
sh 'make test'
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 16:47:10 +00:00
|
|
|
|
2022-02-11 17:13:04 +00:00
|
|
|
// Scan via trivy
|
|
|
|
stage('Scan') {
|
|
|
|
environment {
|
|
|
|
TRIVY_FORMAT = "template"
|
|
|
|
TRIVY_OUTPUT = "reports/trivy.html"
|
|
|
|
}
|
|
|
|
steps {
|
2023-04-03 09:28:13 +00:00
|
|
|
sh 'mkdir -p reports && make scan'
|
2022-02-11 17:13:04 +00:00
|
|
|
publishHTML target: [
|
|
|
|
allowMissing: true,
|
|
|
|
alwaysLinkToLastBuild: true,
|
|
|
|
keepAll: true,
|
|
|
|
reportDir: 'reports',
|
|
|
|
reportFiles: 'trivy.html',
|
|
|
|
reportName: 'TrivyScan',
|
|
|
|
reportTitles: 'TrivyScan'
|
|
|
|
]
|
2022-02-11 16:47:10 +00:00
|
|
|
|
2022-02-14 13:13:11 +00:00
|
|
|
// Scan again and fail on CRITICAL vulns, if not overridden
|
|
|
|
script {
|
|
|
|
if (config.trivyFail == 'NONE') {
|
|
|
|
echo 'trivyFail == NONE, review Trivy report manually. Proceeding ...'
|
|
|
|
} else {
|
|
|
|
sh "TRIVY_EXIT_CODE=1 TRIVY_SEVERITY=${config.trivyFail} make scan"
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 17:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-11 16:47:10 +00:00
|
|
|
|
2023-04-03 09:28:13 +00:00
|
|
|
// Push to container registry, skip if PR
|
2022-02-11 17:13:04 +00:00
|
|
|
stage('Push') {
|
2023-04-03 09:28:13 +00:00
|
|
|
when { not { changeRequest() } }
|
2022-02-11 17:13:04 +00:00
|
|
|
steps {
|
|
|
|
sh 'make push'
|
|
|
|
}
|
|
|
|
}
|
2022-02-14 12:13:28 +00:00
|
|
|
|
2022-02-11 17:13:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|