From 90e51184058d4d6b551359cafdeb9db8b9019241 Mon Sep 17 00:00:00 2001 From: Bram Driesen Date: Tue, 18 Oct 2022 15:00:42 +0200 Subject: [PATCH 01/17] fix: Docker tags break with uppercase branches Added .toLowerCase() to transform uppercase branch names to lowercase. --- src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy b/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy index afbd835..d67aa5e 100644 --- a/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy @@ -51,7 +51,7 @@ class ConventionalCommitPlugin extends Plugin { return version } - return this.deduplicate(script, env.BRANCH_NAME.replaceAll('[^0-9a-zA-Z-]', '-')) + return this.deduplicate(script, env.BRANCH_NAME.replaceAll('[^0-9a-zA-Z-]', '-').toLowerCase()) } } From df06db27050a9cf05457f5ad69dd04674d6baac8 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Tue, 18 Oct 2022 18:31:41 +0200 Subject: [PATCH 02/17] fix(sonarqube): Cleanup workdir --- src/io/stenic/jpipe/plugin/SonarQubePlugin.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/io/stenic/jpipe/plugin/SonarQubePlugin.groovy b/src/io/stenic/jpipe/plugin/SonarQubePlugin.groovy index bfb7996..05de70d 100644 --- a/src/io/stenic/jpipe/plugin/SonarQubePlugin.groovy +++ b/src/io/stenic/jpipe/plugin/SonarQubePlugin.groovy @@ -37,6 +37,9 @@ class SonarQubePlugin extends Plugin { event.script.withSonarQubeEnv(credentialsId: this.credentialsId) { event.script.sh "${this.command} -Dsonar.projectKey=${this.projectKey} -Dsonar.projectVersion=${event.version} ${this.extraArguments.join(' ')}" } + try { + event.script.sh "rm -rf .scannerwork" + } catch (Exception e) {} } } catch (Exception e) { if (this.allowFailure) { From a94625f8878da24f80610a6614603c2246ad3b49 Mon Sep 17 00:00:00 2001 From: Joeri van Dooren Date: Wed, 28 Dec 2022 22:33:29 +0100 Subject: [PATCH 03/17] feat(trivy): Add XML format support --- src/io/stenic/jpipe/plugin/TrivyPlugin.groovy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy index 70cc2a4..0b9e5ad 100644 --- a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy @@ -12,7 +12,7 @@ class TrivyPlugin extends Plugin { private List severity; private String trivyVersion; private String report; - + TrivyPlugin(Map opts = [:]) { this.report = opts.get('report', 'table'); this.allowFailure = opts.get('allowFailure', false); @@ -45,6 +45,8 @@ class TrivyPlugin extends Plugin { ] if (this.report == 'html') { args.add('--format template --template "@contrib/html.tpl" -o /report/report.html') + } else if (this.report == 'xml') { + args.add('--format template --template "@contrib/junit.tpl" -o /report/report.xml') } if (this.ignoreUnfixed == true) { args.add('--ignore-unfixed') @@ -80,6 +82,10 @@ class TrivyPlugin extends Plugin { reportFiles: 'report.html', reportName: "Trivy - ${imgName}", ]) + } else if (this.report == 'xml') { + event.script.recordIssues tools: [event.script.trivy(pattern: '/report/report.xml', reportEncoding: 'UTF-8')], + enabledForFailure: true, + aggregatingResults: true } } } From 196d5bd39cec8aa25c5681b82a1c8b1a381a3a2a Mon Sep 17 00:00:00 2001 From: Joeri van Dooren Date: Wed, 28 Dec 2022 22:49:12 +0100 Subject: [PATCH 04/17] fix(trivy): Use correct report location --- src/io/stenic/jpipe/plugin/TrivyPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy index 0b9e5ad..94b13de 100644 --- a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy @@ -83,7 +83,7 @@ class TrivyPlugin extends Plugin { reportName: "Trivy - ${imgName}", ]) } else if (this.report == 'xml') { - event.script.recordIssues tools: [event.script.trivy(pattern: '/report/report.xml', reportEncoding: 'UTF-8')], + event.script.recordIssues tools: [event.script.trivy(pattern: ".trivy-report-${imgName}/report.xml", reportEncoding: 'UTF-8')], enabledForFailure: true, aggregatingResults: true } From a71394d8b8601b8ab99e146eedf71145b1089871 Mon Sep 17 00:00:00 2001 From: Joeri van Dooren Date: Wed, 28 Dec 2022 22:55:02 +0100 Subject: [PATCH 05/17] fix(trivy): Optimizations --- src/io/stenic/jpipe/plugin/TrivyPlugin.groovy | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy index 94b13de..d136bb6 100644 --- a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy @@ -83,9 +83,10 @@ class TrivyPlugin extends Plugin { reportName: "Trivy - ${imgName}", ]) } else if (this.report == 'xml') { - event.script.recordIssues tools: [event.script.trivy(pattern: ".trivy-report-${imgName}/report.xml", reportEncoding: 'UTF-8')], - enabledForFailure: true, - aggregatingResults: true + event.script.recordIssues tool: event.script.trivy( + pattern: ".trivy-report-${imgName}/report.xml", + reportEncoding: 'UTF-8' + ) } } } From 9db94b6eaa86a6b97322e492c11d3aa9f5cdd13b Mon Sep 17 00:00:00 2001 From: Joeri van Dooren Date: Wed, 28 Dec 2022 23:19:21 +0100 Subject: [PATCH 06/17] fix(trivy): Switch XML support to JSON --- src/io/stenic/jpipe/plugin/TrivyPlugin.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy index d136bb6..5121c94 100644 --- a/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/TrivyPlugin.groovy @@ -45,8 +45,8 @@ class TrivyPlugin extends Plugin { ] if (this.report == 'html') { args.add('--format template --template "@contrib/html.tpl" -o /report/report.html') - } else if (this.report == 'xml') { - args.add('--format template --template "@contrib/junit.tpl" -o /report/report.xml') + } else if (this.report == 'json') { + args.add('--format json -o /report/report.json') } if (this.ignoreUnfixed == true) { args.add('--ignore-unfixed') @@ -82,9 +82,9 @@ class TrivyPlugin extends Plugin { reportFiles: 'report.html', reportName: "Trivy - ${imgName}", ]) - } else if (this.report == 'xml') { + } else if (this.report == 'json') { event.script.recordIssues tool: event.script.trivy( - pattern: ".trivy-report-${imgName}/report.xml", + pattern: ".trivy-report-${imgName}/report.json", reportEncoding: 'UTF-8' ) } From bff6557300e65f02248132f895035770c9b6f8f8 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Fri, 17 Mar 2023 20:38:15 +0100 Subject: [PATCH 07/17] fix: Rename config to ensure type: module works --- .../jpipe/release/{release.config.js => release.config.cjs} | 0 src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename resources/io/stenic/jpipe/release/{release.config.js => release.config.cjs} (100%) diff --git a/resources/io/stenic/jpipe/release/release.config.js b/resources/io/stenic/jpipe/release/release.config.cjs similarity index 100% rename from resources/io/stenic/jpipe/release/release.config.js rename to resources/io/stenic/jpipe/release/release.config.cjs diff --git a/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy b/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy index 9eac3b4..e2ce9cf 100644 --- a/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy @@ -81,7 +81,7 @@ class ConventionalCommitPlugin extends Plugin { private runRelease(script, cmdArgs) { Boolean configCreated = false - String configFile = 'release.config.js' + String configFile = 'release.config.cjs' if (!script.fileExists("./${configFile}")) { def releasercCfg = script.libraryResource "io/stenic/jpipe/release/${configFile}" script.writeFile file: configFile, text: releasercCfg From 64e414fe46ea04489ce471831b23763e4ea85bfd Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Mon, 20 Mar 2023 21:07:42 +0100 Subject: [PATCH 08/17] fix(secretScanner): Correct name --- src/io/stenic/jpipe/plugin/SecretFinderPlugin.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/io/stenic/jpipe/plugin/SecretFinderPlugin.groovy b/src/io/stenic/jpipe/plugin/SecretFinderPlugin.groovy index bdc2b97..d5e5ad6 100644 --- a/src/io/stenic/jpipe/plugin/SecretFinderPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/SecretFinderPlugin.groovy @@ -5,7 +5,7 @@ import java.lang.Exception class SecretFinderPlugin extends Plugin { - public static final String TURTLEHOG = "TURTLEHOG"; + public static final String TRUFFELHOG = "TRUFFELHOG"; private Boolean allowFailure; private String trufflehogImage; @@ -14,7 +14,7 @@ class SecretFinderPlugin extends Plugin { SecretFinderPlugin(Map opts = [:]) { this.allowFailure = opts.get('allowFailure', false); this.trufflehogImage = opts.get('trufflehogImage', 'trufflesecurity/trufflehog:latest'); - this.scanners = opts.get('scanners', [this.TURTLEHOG]); + this.scanners = opts.get('scanners', [this.TRUFFELHOG]); } public Map getSubscribedEvents() { @@ -27,7 +27,7 @@ class SecretFinderPlugin extends Plugin { public void doScan(Event event) { try { - if (this.scanners.contains(this.TURTLEHOG)) { + if (this.scanners.contains(this.TRUFFELHOG)) { doTrufflehogScan(event) } } catch (Exception e) { From b0b2e2e44f04ed3cf0e4907811af19ffbfdaa8aa Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Mon, 20 Mar 2023 21:20:41 +0100 Subject: [PATCH 09/17] feat(cd): Add lock if available --- .../jpipe/plugin/CDInfraAsCodePlugin.groovy | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy b/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy index 9641564..a67a267 100644 --- a/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy +++ b/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy @@ -5,26 +5,26 @@ import org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException class CDInfraAsCodePlugin extends Plugin { - private String yqDockerImage; - private String credentialId; - private String repository; - private String branch; - private String filePath; - private String yamlPath; - private String cdBranch; - private String gitUser; - private String gitEmail; + private String yqDockerImage + private String credentialId + private String repository + private String branch + private String filePath + private String yamlPath + private String cdBranch + private String gitUser + private String gitEmail CDInfraAsCodePlugin(Map opts = [:]) { - this.repository = opts.get('repository', ''); - this.credentialId = opts.get('credentialId', ''); - this.cdBranch = opts.get('cdBranch', 'main'); - this.branch = opts.get('branch', 'master'); - this.yamlPath = opts.get('yamlPath', '.image.tag'); - this.filePath = opts.get('filePath', 'values.yaml'); - this.gitUser = opts.get('gitUser', 'jpipe-ci'); - this.gitEmail = opts.get('gitEmail', 'jpipe@stenic.io'); - this.yqDockerImage = opts.get('dockerImage', 'mikefarah/yq:4'); + this.repository = opts.get('repository', '') + this.credentialId = opts.get('credentialId', '') + this.cdBranch = opts.get('cdBranch', 'main') + this.branch = opts.get('branch', 'master') + this.yamlPath = opts.get('yamlPath', '.image.tag') + this.filePath = opts.get('filePath', 'values.yaml') + this.gitUser = opts.get('gitUser', 'jpipe-ci') + this.gitEmail = opts.get('gitEmail', 'jpipe@stenic.io') + this.yqDockerImage = opts.get('dockerImage', 'mikefarah/yq:4') } public Map getSubscribedEvents() { @@ -36,25 +36,35 @@ class CDInfraAsCodePlugin extends Plugin { } public Boolean doYamlUpdate(Event event) { - if (this.cdBranch == "" || event.env.BRANCH_NAME != this.cdBranch) { - event.script.println("Skipping CDInfraAsCodePlugin") - return true; + if (this.cdBranch == '' || event.env.BRANCH_NAME != this.cdBranch) { + event.script.println('Skipping CDInfraAsCodePlugin') + return true } if (this.credentialId == '') { - this.credentialId = event.script.scm.getUserRemoteConfigs()[0].getCredentialsId(); + this.credentialId = event.script.scm.getUserRemoteConfigs()[0].getCredentialsId() } - event.script.dir( "${System.currentTimeMillis()}" ) { + if (event.script.metaClass.properties.find { it.name == 'lock' } != null) { + event.script.lock("infrarepo-${this.repository}") { + return this.doCommit(event) + } + } + + return this.doCommit(event) +} + + private Boolean doCommit(Event event) { + event.script.dir("${System.currentTimeMillis()}") { event.script.git( url: this.repository, branch: this.branch, credentialsId: this.credentialId, changelog: false - ); + ) event.script.docker.image(this.yqDockerImage).inside("--entrypoint=''") { - event.script.sh "yq eval --inplace '${this.yamlPath} = \"${event.version}\"' ${this.filePath}"; + event.script.sh "yq eval --inplace '${this.yamlPath} = \"${event.version}\"' ${this.filePath}" } event.script.sshagent(credentials: [this.credentialId]) { @@ -66,7 +76,6 @@ class CDInfraAsCodePlugin extends Plugin { event.script.sh "git push origin ${this.branch}" } } - - return true } + } From f47057fe985c880fae6baf18a123ae7b634d597d Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Fri, 24 Mar 2023 13:21:00 +0100 Subject: [PATCH 10/17] fix: Format and rebuild image --- src/io/stenic/jpipe/plugin/EcrPlugin.groovy | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/io/stenic/jpipe/plugin/EcrPlugin.groovy b/src/io/stenic/jpipe/plugin/EcrPlugin.groovy index d6a7274..a33a6d5 100644 --- a/src/io/stenic/jpipe/plugin/EcrPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/EcrPlugin.groovy @@ -4,15 +4,15 @@ import io.stenic.jpipe.event.Event class EcrPlugin extends Plugin { - protected String dockerImage = 'amazon/aws-cli'; - private String credentialsId; - private String repository; - private String region; + protected String dockerImage = 'amazon/aws-cli' + private String credentialsId + private String repository + private String region EcrPlugin(Map opts = [:]) { - this.repository = opts.get('repository', ''); - this.credentialsId = opts.get('credentialsId', ''); - this.region = opts.get('region', ''); + this.repository = opts.get('repository', '') + this.credentialsId = opts.get('credentialsId', '') + this.region = opts.get('region', '') } public Map getSubscribedEvents() { @@ -41,4 +41,5 @@ class EcrPlugin extends Plugin { } } } + } From 17cf03b69d0cc994bd5b56e4dea6600aea0e144f Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 24 Mar 2023 12:22:12 +0000 Subject: [PATCH 11/17] chore(release): 1.3.1 ## [1.3.1](https://github.com/stenic/jpipe/compare/v1.3.0...v1.3.1) (2023-03-24) ### Bug Fixes * Format and rebuild image ([0bb9752](https://github.com/stenic/jpipe/commit/0bb9752a4ef14556b3fd87526ac7ffea702739ba)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06a9ac5..ff55c9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.3.1](https://github.com/stenic/jpipe/compare/v1.3.0...v1.3.1) (2023-03-24) + + +### Bug Fixes + +* Format and rebuild image ([0bb9752](https://github.com/stenic/jpipe/commit/0bb9752a4ef14556b3fd87526ac7ffea702739ba)) + # [1.3.0](https://github.com/stenic/jpipe/compare/v1.2.2...v1.3.0) (2023-03-16) From 2a3c54875ea7bad3e64e028a4996494d12754deb Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Fri, 24 Mar 2023 13:24:06 +0100 Subject: [PATCH 12/17] fix: Format and rebuild image --- src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy b/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy index e2ce9cf..ff3cba7 100644 --- a/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/ConventionalCommitPlugin.groovy @@ -4,7 +4,7 @@ import io.stenic.jpipe.event.Event class ConventionalCommitPlugin extends Plugin { - protected String dockerImage = 'ghcr.io/stenic/jpipe-release:1.2' + protected String dockerImage = 'ghcr.io/stenic/jpipe-release:1.3' private Boolean useSemanticRelease = false private String releaseBranches From cc78253b7687bb8e6707d7b6193205ebed3752f4 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 24 Mar 2023 12:25:28 +0000 Subject: [PATCH 13/17] chore(release): 1.3.2 ## [1.3.2](https://github.com/stenic/jpipe/compare/v1.3.1...v1.3.2) (2023-03-24) ### Bug Fixes * Format and rebuild image ([068d8ab](https://github.com/stenic/jpipe/commit/068d8ab0b96172ad87a0c0ac781270a43ec21c03)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff55c9a..b9e2ed9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.3.2](https://github.com/stenic/jpipe/compare/v1.3.1...v1.3.2) (2023-03-24) + + +### Bug Fixes + +* Format and rebuild image ([068d8ab](https://github.com/stenic/jpipe/commit/068d8ab0b96172ad87a0c0ac781270a43ec21c03)) + ## [1.3.1](https://github.com/stenic/jpipe/compare/v1.3.0...v1.3.1) (2023-03-24) From 57c66be32c11ca4b4795a05c6f93c21db8749f47 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Fri, 24 Mar 2023 13:41:33 +0100 Subject: [PATCH 14/17] fix: github host-key entry https://github.blog/2023-03-23-we-updated-our-rsa-ssh-host-key/ --- images/release/Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/images/release/Dockerfile b/images/release/Dockerfile index bc06f08..80af598 100644 --- a/images/release/Dockerfile +++ b/images/release/Dockerfile @@ -15,8 +15,11 @@ RUN npm install -g \ WORKDIR /app RUN mkdir -p /home/node/.ssh/ \ - && ssh-keyscan -t rsa github.com >> /home/node/.ssh/known_hosts \ && ssh-keyscan -t rsa gitlab.com >> /home/node/.ssh/known_hosts \ - && ssh-keyscan -t rsa bitbucket.org >> /home/node/.ssh/known_hosts + && ssh-keyscan -t rsa bitbucket.org >> /home/node/.ssh/known_hosts \ + && ssh-keyscan -t rsa github.com >> /home/node/.ssh/known_hosts \ + && apk add --no-cache --virtual tooling jq curl \ + && curl -L https://api.github.com/meta | jq -r '.ssh_keys | .[]' | sed -e 's/^/github.com /' >> /home/node/.ssh/known_hosts \ + && apk del tooling ENTRYPOINT [""] From 81815dd5b8d2c6394b1ef11cd0116424801231df Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 24 Mar 2023 12:43:15 +0000 Subject: [PATCH 15/17] chore(release): 1.3.3 ## [1.3.3](https://github.com/stenic/jpipe/compare/v1.3.2...v1.3.3) (2023-03-24) ### Bug Fixes * github host-key entry https://github.blog/2023-03-23-we-updated-our-rsa-ssh-host-key/ ([b9a435b](https://github.com/stenic/jpipe/commit/b9a435bcdb4e42fe15f6d0f025e0b9bdf014536b)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9e2ed9..309cc22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.3.3](https://github.com/stenic/jpipe/compare/v1.3.2...v1.3.3) (2023-03-24) + + +### Bug Fixes + +* github host-key entry https://github.blog/2023-03-23-we-updated-our-rsa-ssh-host-key/ ([b9a435b](https://github.com/stenic/jpipe/commit/b9a435bcdb4e42fe15f6d0f025e0b9bdf014536b)) + ## [1.3.2](https://github.com/stenic/jpipe/compare/v1.3.1...v1.3.2) (2023-03-24) From dd19646406f3a4eb778cbf00cbaf878b73e35067 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Wed, 7 Jun 2023 11:36:58 +0200 Subject: [PATCH 16/17] fix: Allow locking --- src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy b/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy index a67a267..6303df1 100644 --- a/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy +++ b/src/io/stenic/jpipe/plugin/CDInfraAsCodePlugin.groovy @@ -45,7 +45,7 @@ class CDInfraAsCodePlugin extends Plugin { this.credentialId = event.script.scm.getUserRemoteConfigs()[0].getCredentialsId() } - if (event.script.metaClass.properties.find { it.name == 'lock' } != null) { + if (this.hasPlugin('lockable-resources')) { event.script.lock("infrarepo-${this.repository}") { return this.doCommit(event) } @@ -78,4 +78,12 @@ class CDInfraAsCodePlugin extends Plugin { } } + private Boolean hasPlugin(String pluginName) { + try { + return jenkins.model.Jenkins.instance.getPluginManager().getPlugin(pluginName) != null + } catch (RejectedAccessException e) { + return false + } + } + } From 30dd4225f3a3e3610258ffe720f35c7c13ca7980 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Wed, 5 Jul 2023 14:22:17 +0200 Subject: [PATCH 17/17] fix: Add version to main build --- .../stenic/jpipe/plugin/DockerPlugin.groovy | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/io/stenic/jpipe/plugin/DockerPlugin.groovy b/src/io/stenic/jpipe/plugin/DockerPlugin.groovy index e3c217e..4c616ec 100644 --- a/src/io/stenic/jpipe/plugin/DockerPlugin.groovy +++ b/src/io/stenic/jpipe/plugin/DockerPlugin.groovy @@ -4,34 +4,34 @@ import io.stenic.jpipe.event.Event class DockerPlugin extends Plugin { - private String credentialId; - private String server; - private String repository; - private String buildArgs; - private String target; - private Boolean push; - private String filePath; - private String testScript; - private List extraTargets; - private List extraTags; - private Boolean useCache; - private Boolean doCleanup; - private String buildArgVersionKey; + private String credentialId + private String server + private String repository + private String buildArgs + private String target + private Boolean push + private String filePath + private String testScript + private List extraTargets + private List extraTags + private Boolean useCache + private Boolean doCleanup + private String buildArgVersionKey DockerPlugin(Map opts = [:]) { - this.repository = opts.get('repository', ''); - this.credentialId = opts.get('credentialId', ''); - this.server = opts.get('server', 'http://index.docker.io'); - this.buildArgs = opts.get('buildArgs', ''); - this.push = opts.get('push', this.credentialId != ''); - this.filePath = opts.get('filePath', '.'); - this.target = opts.get('target', ''); - this.extraTargets = opts.get('extraTargets', []); - this.extraTags = opts.get('extraTags', []); - this.testScript = opts.get('testScript', ''); - this.useCache = opts.get('useCache', true); - this.doCleanup = opts.get('doCleanup', false); - this.buildArgVersionKey = opts.get('buildArgVersionKey', 'VERSION'); + this.repository = opts.get('repository', '') + this.credentialId = opts.get('credentialId', '') + this.server = opts.get('server', 'http://index.docker.io') + this.buildArgs = opts.get('buildArgs', '') + this.push = opts.get('push', this.credentialId != '') + this.filePath = opts.get('filePath', '.') + this.target = opts.get('target', '') + this.extraTargets = opts.get('extraTargets', []) + this.extraTags = opts.get('extraTags', []) + this.testScript = opts.get('testScript', '') + this.useCache = opts.get('useCache', true) + this.doCleanup = opts.get('doCleanup', false) + this.buildArgVersionKey = opts.get('buildArgVersionKey', 'VERSION') } public Map getSubscribedEvents() { @@ -57,8 +57,8 @@ class DockerPlugin extends Plugin { this.extraTargets.each { target -> event.script.docker.image("${this.repository}:cache-${target}").pull() } - } catch(Exception e) {} - } + } catch (Exception e) { } + } def buildArgs = this.buildArgs if (this.target != '') { @@ -71,7 +71,7 @@ class DockerPlugin extends Plugin { event.script.sshagent(credentials: [event.script.scm.getUserRemoteConfigs()[0].getCredentialsId()]) { event.script.docker.build( "${this.repository}:${event.version}", - "${buildArgs} ${this.filePath}" + "${buildArgs} --build-arg ${this.buildArgVersionKey}=${event.version} ${this.filePath}" ) this.extraTags.each { tag -> event.script.sh "docker tag ${this.repository}:${event.version} ${this.repository}:${tag}" @@ -84,8 +84,8 @@ class DockerPlugin extends Plugin { } } } + } } - } public void doTest(Event event) { if (this.testScript != '') { @@ -108,11 +108,11 @@ class DockerPlugin extends Plugin { this.extraTargets.each { target -> event.script.docker.image("${this.repository}:${target}").push("cache-${target}") } - } catch(Exception e) {} + } catch (Exception e) { } + } } } } - } public void doDockerCleanup(Event event) { if (!this.doCleanup) { @@ -133,6 +133,7 @@ class DockerPlugin extends Plugin { } } event.script.sh 'docker rmi -f $(docker images -f "dangling=true" -q)' - } catch(Exception e) {} + } catch (Exception e) { } + } + } -}