11#! /usr/bin/env groovy
22
3+ // Automated release, promotion and dependencies
4+ properties([
5+ // Include the automated release parameters for the build
6+ release. addParams(),
7+ ])
8+
9+ // Performs release promotion. No other stages will be run
10+ if (params. MODE == " PROMOTE" ) {
11+ release. promote(params. VERSION_TO_PROMOTE ) { sourceVersion , targetVersion , assetDirectory ->
12+ // Any assets from sourceVersion Github release are available in assetDirectory
13+ // Any version number updates from sourceVersion to targetVersion occur here
14+ // Any publishing of targetVersion artifacts occur here
15+ // Anything added to assetDirectory will be attached to the Github Release
16+ }
17+ return
18+ }
19+
320pipeline {
421 agent { label ' executor-v2' }
522
@@ -9,20 +26,46 @@ pipeline {
926 timeout(time : 2 , unit : ' HOURS' )
1027 }
1128
29+ triggers {
30+ cron(getDailyCronString())
31+ }
32+
1233 environment {
1334 // Sets the MODE to the specified or autocalculated value as appropriate
1435 MODE = release. canonicalizeMode()
1536 }
1637
1738 stages {
18- stage(' Validate' ) {
19- parallel {
20- stage(' Changelog' ) {
21- steps { sh ' ./bin/parse_changelog' }
39+ // Aborts any builds triggered by another project that wouldn't include any changes
40+ stage (" Skip build if triggering job didn't create a release" ) {
41+ when {
42+ expression {
43+ MODE == " SKIP"
44+ }
45+ }
46+ steps {
47+ script {
48+ currentBuild. result = ' ABORTED'
49+ error(" Aborting build because this build was triggered from upstream, but no release was built" )
2250 }
2351 }
2452 }
2553
54+ // Generates a VERSION file based on the current build number and latest version in CHANGELOG.md
55+ stage(' Validate Changelog and set version' ) {
56+ steps {
57+ sh ' ./bin/parse_changelog'
58+ updateVersion(" CHANGELOG.md" , " ${ BUILD_NUMBER} " )
59+ }
60+ }
61+
62+ stage(' Get latest upstream dependencies' ) {
63+ steps {
64+ updateGoDependencies(' ${WORKSPACE}/go.mod' )
65+ }
66+ }
67+
68+
2669 stage(' Run Unit Tests' ) {
2770 steps {
2871 sh ' ./bin/test_unit'
@@ -44,5 +87,34 @@ pipeline {
4487 ccCoverage(" gocov" , " --prefix github.com/conjurinc/conjur-preflight" )
4588 }
4689 }
90+
91+ stage(' Release' ) {
92+ when {
93+ expression {
94+ MODE == " RELEASE"
95+ }
96+ }
97+
98+ steps {
99+ // Build release artifacts
100+ sh " bin/build_release"
101+
102+ release { billOfMaterialsDirectory , assetDirectory , toolsDirectory ->
103+ // Publish release artifacts to all the appropriate locations
104+ // Copy any artifacts to assetDirectory to attach them to the Github release
105+
106+ // Create Go application SBOM using the go.mod version for the golang container image
107+ sh """ go-bom --tools "${ toolsDirectory} " --go-mod ./go.mod --image "golang" --main "cmd/conjur-preflight/" --output "${ billOfMaterialsDirectory} /go-app-bom.json" """
108+ // Create Go module SBOM
109+ sh """ go-bom --tools "${ toolsDirectory} " --go-mod ./go.mod --image "golang" --output "${ billOfMaterialsDirectory} /go-mod-bom.json" """
110+
111+ // Add goreleaser artifacts to release
112+ sh """ cp dist/*.tar.gz "${ assetDirectory} " """
113+ sh """ cp dist/*.rpm "${ assetDirectory} " """
114+ sh """ cp dist/*.deb "${ assetDirectory} " """
115+ sh """ cp "dist/SHA256SUMS.txt" "${ assetDirectory} " """
116+ }
117+ }
118+ }
47119 }
48120}
0 commit comments