|
| 1 | +AGENT_YAML = ''' |
| 2 | + apiVersion: v1 |
| 3 | + kind: Pod |
| 4 | + metadata: |
| 5 | + namespace: oss-agent |
| 6 | + spec: |
| 7 | + serviceAccountName: oss-agent |
| 8 | + containers: |
| 9 | + - name: maven |
| 10 | + image: maven:3.8.6-openjdk-8-slim |
| 11 | + tty: true |
| 12 | + resources: |
| 13 | + requests: |
| 14 | + memory: "1Gi" |
| 15 | + cpu: "500m" |
| 16 | + limits: |
| 17 | + memory: "1Gi" |
| 18 | + cpu: "500m" |
| 19 | + command: |
| 20 | + - cat |
| 21 | +''' |
| 22 | + |
| 23 | +pipeline { |
| 24 | + |
| 25 | + agent { |
| 26 | + kubernetes { |
| 27 | + defaultContainer 'maven' |
| 28 | + yaml AGENT_YAML |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + environment { |
| 33 | + GPG_SECRET = credentials('presto-release-gpg-secret') |
| 34 | + GPG_TRUST = credentials("presto-release-gpg-trust") |
| 35 | + GPG_PASSPHRASE = credentials("presto-release-gpg-passphrase") |
| 36 | + |
| 37 | + GITHUB_OSS_TOKEN_ID = 'github-personal-token-wanglinsong' |
| 38 | + |
| 39 | + SONATYPE_NEXUS_CREDS = credentials('presto-sonatype-nexus-creds') |
| 40 | + SONATYPE_NEXUS_PASSWORD = "$SONATYPE_NEXUS_CREDS_PSW" |
| 41 | + SONATYPE_NEXUS_USERNAME = "$SONATYPE_NEXUS_CREDS_USR" |
| 42 | + } |
| 43 | + |
| 44 | + options { |
| 45 | + buildDiscarder(logRotator(numToKeepStr: '100')) |
| 46 | + disableConcurrentBuilds() |
| 47 | + disableResume() |
| 48 | + overrideIndexTriggers(false) |
| 49 | + timeout(time: 30, unit: 'MINUTES') |
| 50 | + timestamps() |
| 51 | + } |
| 52 | + |
| 53 | + parameters { |
| 54 | + booleanParam(name: 'PERFORM_MAVEN_RELEASE', |
| 55 | + defaultValue: false, |
| 56 | + description: 'Release and update development version when running in the master') |
| 57 | + } |
| 58 | + |
| 59 | + stages { |
| 60 | + stage('Setup') { |
| 61 | + steps { |
| 62 | + sh 'apt update && apt install -y bash build-essential git gpg python3 python3-venv' |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + stage ('Prepare to Release') { |
| 67 | + steps { |
| 68 | + script { |
| 69 | + env.REPO_CURRENT_VERSION = sh( |
| 70 | + script: 'mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -ntp -DforceStdout', |
| 71 | + returnStdout: true).trim() |
| 72 | + } |
| 73 | + echo "current version: ${REPO_CURRENT_VERSION}" |
| 74 | + |
| 75 | + sh ''' |
| 76 | + git config --global --add safe.directory ${PWD} |
| 77 | + git config --global user.email "oss-release-bot@prestodb.io" |
| 78 | + git config --global user.name "oss-release-bot" |
| 79 | + ''' |
| 80 | + |
| 81 | + sh ''' |
| 82 | + mvn release:prepare -B -DskipTests \ |
| 83 | + -DautoVersionSubmodules=true \ |
| 84 | + -DgenerateBackupPoms=false |
| 85 | +
|
| 86 | + git branch |
| 87 | + git log --pretty="format:%ce: %s" -8 |
| 88 | + SCM_TAG=$(cat release.properties | grep scm.tag=) |
| 89 | + echo ${SCM_TAG#*=} > repo-release-tag.txt |
| 90 | + ''' |
| 91 | + |
| 92 | + script { |
| 93 | + env.REPO_RELEASE_TAG = sh( |
| 94 | + script: 'cat repo-release-tag.txt', |
| 95 | + returnStdout: true).trim() |
| 96 | + } |
| 97 | + echo "release tag: ${REPO_RELEASE_TAG}" |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + stage ('Release Maven Artifacts') { |
| 102 | + when { |
| 103 | + allOf { |
| 104 | + expression { params.PERFORM_MAVEN_RELEASE } |
| 105 | + branch 'master' |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + steps { |
| 110 | + echo "Update GitHub Repo" |
| 111 | + withCredentials([usernamePassword( |
| 112 | + credentialsId: "${GITHUB_OSS_TOKEN_ID}", |
| 113 | + passwordVariable: 'GIT_PASSWORD', |
| 114 | + usernameVariable: 'GIT_USERNAME')]) { |
| 115 | + sh ''' |
| 116 | + git switch -c master |
| 117 | + git branch |
| 118 | +
|
| 119 | + git --no-pager log --since="60 days ago" --graph --pretty=format:'%C(auto)%h%d%Creset %C(cyan)(%cd)%Creset %C(green)%cn <%ce>%Creset %s' |
| 120 | + head -n 18 pom.xml |
| 121 | + ORIGIN="https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/prestodb/airlift.git" |
| 122 | + git push --follow-tags --set-upstream ${ORIGIN} master |
| 123 | + ''' |
| 124 | + } |
| 125 | + |
| 126 | + echo "Release ${REPO_RELEASE_TAG} maven artifacts" |
| 127 | + sh '''#!/bin/bash -ex |
| 128 | + export GPG_TTY=$TTY |
| 129 | + gpg --batch --import ${GPG_SECRET} |
| 130 | + echo ${GPG_TRUST} | gpg --import-ownertrust - |
| 131 | + gpg --list-secret-keys |
| 132 | + echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf |
| 133 | + printenv | sort |
| 134 | +
|
| 135 | + git checkout ${REPO_RELEASE_TAG} |
| 136 | + git status |
| 137 | + git branch |
| 138 | + git log -8 |
| 139 | + head -n 18 pom.xml |
| 140 | +
|
| 141 | + mvn -s ${WORKSPACE}/jenkins/settings.xml -V -B -U -e -T2C deploy \ |
| 142 | + -DautoReleaseAfterClose=true \ |
| 143 | + -Dgpg.passphrase=${GPG_PASSPHRASE} \ |
| 144 | + -DkeepStagingRepositoryOnCloseRuleFailure=true \ |
| 145 | + -DkeepStagingRepositoryOnFailure=true \ |
| 146 | + -DskipTests \ |
| 147 | + -Poss-release \ |
| 148 | + -Pdeploy-to-ossrh \ |
| 149 | + -DstagingProgressTimeoutMinutes=10 |
| 150 | + ''' |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments