From 09dff985092d9eb901fcfbf7d325a9f789379485 Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Tue, 30 May 2023 16:19:34 +0300 Subject: [PATCH] Create tag and GitHub Release on release pipeline (#1953) --- Jenkinsfile | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 228e0185b..490f1f8bb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -97,9 +97,10 @@ def runRelease(architectures) { // Download cert files, to be used for signing the Windows executable, packaged by Chocolatey. downloadToolsCert() stage('Build and publish Chocolatey') { - publishChocoPackage(version, jfrogCliRepoDir, architectures) + publishChocoPackageWithRetries(version, jfrogCliRepoDir, architectures) } } else if ("$EXECUTION_MODE".toString().equals("Build CLI")) { + validateReleaseVersion() if (identifier != "v2") { stage("Audit") { dir("$jfrogCliRepoDir") { @@ -131,12 +132,50 @@ def runRelease(architectures) { } } } + if (identifier == "v2") { + createTagAndRelease() + } } } finally { cleanupRepo21() } } +def createTagAndRelease() { + stage('Create a tag and a GitHub release') { + dir("$jfrogCliRepoDir") { + releaseTag = "v$RELEASE_VERSION" + withCredentials([string(credentialsId: 'ecosystem-github-automation', variable: 'GITHUB_ACCESS_TOKEN')]) { + sh """#!/bin/bash + git tag $releaseTag + git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git" --tags + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_ACCESS_TOKEN"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/jfrog/jfrog-cli/releases \ + -d '{"tag_name":"$releaseTag","target_commitish":"$BRANCH","name":"$RELEASE_VERSION","generate_release_notes":true}' + """ + } + } + } +} + +def validateReleaseVersion() { + if (RELEASE_VERSION=="") { + error "RELEASE_VERSION parameter is mandatory on this execution mode" + } + if (RELEASE_VERSION.startsWith("v")) { + error "RELEASE_VERSION parameter should not start with a preceding \"v\"" + } + // Verify version stands in semantic versioning. + def pattern = /^2\.(\d+)\.(\d+)$/ + if (!(RELEASE_VERSION =~ pattern)) { + error "RELEASE_VERSION is not a valid version" + } +} + def downloadToolsCert() { stage('Download tools cert') { // Download the certificate file and key file, used for signing the JFrog CLI binary. @@ -378,6 +417,27 @@ def publishNpmPackage(jfrogCliRepoDir) { } } +def publishChocoPackageWithRetries(version, jfrogCliRepoDir, architectures) { + def maxAttempts = 3 + def currentAttempt = 1 + def waitSeconds = 20 + + while (currentAttempt <= maxAttempts) { + try { + publishChocoPackage(version, jfrogCliRepoDir, architectures) + echo "Successfully published Choco package!" + return + } catch (Exception e) { + echo "Publishing Choco failed on attempt ${currentAttempt}" + currentAttempt++ + if (currentAttempt > maxAttempts) { + error "Max attempts reached. Publishing Choco failed!" + } + sleep waitSeconds + } + } +} + def publishChocoPackage(version, jfrogCliRepoDir, architectures) { def architecture = architectures.find { it.goos == 'windows' && it.goarch == 'amd64' } build(architecture.goos, architecture.goarch, architecture.pkg, "${cliExecutableName}.exe")