Skip to content

Commit

Permalink
Create tag and GitHub Release on release pipeline (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored May 30, 2023
1 parent b1bc678 commit 09dff98
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 09dff98

Please sign in to comment.