2022-02-24 10:54:30 +00:00
|
|
|
// Common container builder by ZeroDownTime
|
|
|
|
|
|
|
|
def call(Map config=[:]) {
|
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
node {
|
|
|
|
label 'podman-aws-trivy'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Prepare') {
|
|
|
|
steps {
|
2023-08-17 09:51:15 +00:00
|
|
|
// we set pull tags as project adv. options
|
2023-05-15 12:21:08 +00:00
|
|
|
// pull tags
|
2023-08-17 09:51:15 +00:00
|
|
|
//withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) {
|
|
|
|
// sh 'git fetch -q --tags ${GIT_URL}'
|
|
|
|
//}
|
2023-08-14 10:20:46 +00:00
|
|
|
// Optional project specific preparations
|
|
|
|
sh 'make prepare'
|
2022-02-24 10:54:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build using rootless podman
|
|
|
|
stage('Build') {
|
|
|
|
steps {
|
2023-08-17 09:51:15 +00:00
|
|
|
sh 'make build GIT_BRANCH=$GIT_BRANCH'
|
2022-02-24 10:54:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Test') {
|
|
|
|
steps {
|
|
|
|
sh 'make test'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan via trivy
|
|
|
|
stage('Scan') {
|
|
|
|
environment {
|
|
|
|
TRIVY_FORMAT = "template"
|
|
|
|
TRIVY_OUTPUT = "reports/trivy.html"
|
|
|
|
}
|
|
|
|
steps {
|
2023-05-15 12:21:08 +00:00
|
|
|
sh 'mkdir -p reports && make scan'
|
2022-02-24 10:54:30 +00:00
|
|
|
publishHTML target: [
|
|
|
|
allowMissing: true,
|
|
|
|
alwaysLinkToLastBuild: true,
|
|
|
|
keepAll: true,
|
|
|
|
reportDir: 'reports',
|
|
|
|
reportFiles: 'trivy.html',
|
|
|
|
reportName: 'TrivyScan',
|
|
|
|
reportTitles: 'TrivyScan'
|
|
|
|
]
|
|
|
|
|
|
|
|
// 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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 10:20:46 +00:00
|
|
|
// Push to container registry if not PR
|
2023-08-14 10:27:13 +00:00
|
|
|
// incl. basic registry retention removing any untagged images
|
2022-02-24 10:54:30 +00:00
|
|
|
stage('Push') {
|
2023-05-15 12:21:08 +00:00
|
|
|
when { not { changeRequest() } }
|
2022-02-24 10:54:30 +00:00
|
|
|
steps {
|
|
|
|
sh 'make push'
|
2023-08-14 10:27:13 +00:00
|
|
|
sh 'make rm-remote-untagged'
|
2022-02-24 10:54:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 10:20:46 +00:00
|
|
|
// generic clean
|
2023-08-09 11:59:00 +00:00
|
|
|
stage('cleanup') {
|
2023-08-14 10:24:11 +00:00
|
|
|
steps {
|
|
|
|
sh 'make clean'
|
|
|
|
}
|
2023-08-09 11:59:00 +00:00
|
|
|
}
|
2022-02-24 10:54:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|