Skip to content

Commit eb51aec

Browse files
committed
[I/Y-Build] Inline scripts for git cloning and tagging and clone earlier
Inlining the scripts into the Jenkinsfile makes it easier to understand the exact steps and simplifies applying temporary changes to the pipeline, for example when trying-out/testing changes.
1 parent e0cea1f commit eb51aec

File tree

5 files changed

+107
-187
lines changed

5 files changed

+107
-187
lines changed

JenkinsJobs/Builds/build.jenkinsfile

Lines changed: 107 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ spec:
3434
environment {
3535
MAVEN_OPTS = '-Xmx4G'
3636
CJE_ROOT = "${WORKSPACE}/cje-production"
37+
AGG_DIR = 'gitCache/eclipse.platform.releng.aggregator'
3738
logDir = "$CJE_ROOT/buildlogs"
3839
}
3940
stages {
@@ -71,6 +72,112 @@ spec:
7172
}
7273
}
7374
}
75+
stage('Clone and tag Build Inputs') {
76+
steps {
77+
sshagent (['github-bot-ssh']) {
78+
sh '''#!/bin/bash -xe
79+
source $CJE_ROOT/buildproperties.shsource
80+
81+
git config --global user.email '[email protected]'
82+
git config --global user.name 'Eclipse Releng Bot'
83+
84+
# Clone this repo and all submodules into the 'AGG_DIR' directory
85+
git clone --branch=$BRANCH --recursive \
86+
[email protected]:eclipse-platform/eclipse.platform.releng.aggregator.git "$CJE_ROOT/$AGG_DIR"
87+
88+
cd "$CJE_ROOT/$AGG_DIR"
89+
90+
git submodule foreach 'git fetch; SUBMODULE_BRANCH=$(grep $name: $CJE_ROOT/streams/repositories_$PATCH_OR_BRANCH_LABEL.txt | cut -f2 -d\\ ); SUBMODULE_BRANCH=${SUBMODULE_BRANCH:-$BRANCH}; echo Checking out $SUBMODULE_BRANCH; git checkout $SUBMODULE_BRANCH; git pull'
91+
92+
# Create 'Build input' commit (considering commits potentially submitted to the aggregator BRANCH in the meantime)
93+
git checkout $BRANCH
94+
git pull
95+
git commit --all --message="Build input for build $BUILD_ID" || echo 'No submodule changes'
96+
97+
if [ "${BUILD_TYPE}" == "I" ]; then
98+
git push --verbose origin $BRANCH
99+
fi
100+
'''
101+
}
102+
dir("${CJE_ROOT}/${AGG_DIR}") {
103+
sshagent (['projects-storage.eclipse.org-bot-ssh']) {
104+
// Try to find the last tag of the current build type that is available as a promoted build
105+
// by checking the most recent 5 tags and seeing if an update site for it exists
106+
sh '''#!/bin/bash -xe
107+
source $CJE_ROOT/buildproperties.shsource
108+
updateSiteRootPath=/home/data/httpd/download.eclipse.org/eclipse/updates/${STREAMMajor}.${STREAMMinor}-${BUILD_TYPE}-builds
109+
lastTagList=$(git tag --list "${BUILD_TYPE}*" | tail -n5 | tac)
110+
for lt in $lastTagList ; do
111+
if ssh [email protected] test -d ${updateSiteRootPath}/${lt} ; then
112+
echo "$lt" > 'lastTag'
113+
exit 0
114+
fi
115+
done
116+
# if no build is promoted yet, then just fallback to the last tag of the current build type
117+
git describe --tags --match "${BUILD_TYPE}*" --abbrev=0 > 'lastTag'
118+
'''
119+
}
120+
script { // Check for changes and abort if nothing changed since the last build
121+
def boolean isScheduledBuild = !currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').isEmpty()
122+
if (isScheduledBuild && sh(script: 'git diff $(cat "${WORKSPACE}/lastTag")..HEAD --name-only', returnStdout: true).trim().isEmpty()) {
123+
emailext subject: "${RELEASE_VER} ${BUILD_TYPE}-Build: ${BUILD_IID} - Build skipped", body: """\
124+
No changes have been made since the last successful ${BUILD_TYPE}-Build and therefore this scheduled build was skipped:
125+
${BUILD_URL}console
126+
""".stripIndent(), mimeType: 'text/plain',
127+
to: "${MAILING_LIST}", from: '[email protected]'
128+
currentBuild.result = 'ABORTED'
129+
error('Abort scheduled build due to no changes')
130+
}
131+
}
132+
// Git tagging
133+
sshagent (['github-bot-ssh']) {
134+
sh '''#!/bin/bash -xe
135+
source $CJE_ROOT/buildproperties.shsource
136+
function toPushRepo() {
137+
from="$1"
138+
echo $(sed --expression 's,https://github.com/,[email protected]:,' <<< $from)
139+
}
140+
export -f toPushRepo
141+
git submodule foreach 'if grep "^${name}:" $CJE_ROOT/streams/repositories_$PATCH_OR_BRANCH_LABEL.txt > /dev/null; then git tag $BUILD_ID; PUSH_URL="$(toPushRepo $(git config --get remote.origin.url))"; git push --verbose $PUSH_URL $BUILD_ID; else echo Skipping $name; fi || :'
142+
git tag $BUILD_ID
143+
git push --verbose origin $BUILD_ID
144+
'''
145+
}
146+
// Git log creation
147+
sh '''#!/bin/bash -xe
148+
source $CJE_ROOT/buildproperties.shsource
149+
reportTimestamp=$(TZ="America/New_York" date +%Y%m%d-%H%M)
150+
export lastTag=$(cat lastTag)
151+
if [[ -n "$lastTag" ]]; then
152+
export gitLogFile="$CJE_ROOT/$DROP_DIR/$BUILD_ID/gitLog.html"
153+
mkdir -p $(dirname "${gitLogFile}")
154+
155+
echo -e "<h2>Git log from $lastTag (previous) to $BUILD_ID (current)</h2>" > $gitLogFile
156+
echo -e "<h2>The tagging, and this report, were done at about $reportTimestamp</h2>" >> $gitLogFile
157+
158+
function createGitLog() {
159+
gitURL=$(git config remote.origin.url | sed --expression 's,[email protected]:,https://github.com/,' | sed 's/\\.git$//')
160+
gitName="${gitURL##*/}"
161+
gitLog=$(git log $lastTag..$BUILD_ID --date=short --format=format:"<tr><td class=\"datecell\">%cd</td><td class=\"commitcell\"><a href=\"${gitURL}/commit/%H\">%s</a></td><td class=\"authorcell\">%aN</td></tr>")
162+
if [ -n "$gitLog" ]; then
163+
echo "Record changes in ${gitName}"
164+
echo "<table><tbody> <tr><th class=\"cell\" colspan=\"3\">Repository: ${gitName}</th></tr>" >> $gitLogFile
165+
echo "<tr> <th class=\"datecell\">Date</th> <th class=\"commitcell\">Commit message</th> <th class=\"authorcell\">Author</th> </tr>" >> $gitLogFile
166+
echo "${gitLog}" >> $gitLogFile
167+
echo "</tbody></table><br><br>" >> $gitLogFile
168+
echo '' >> $gitLogFile
169+
fi
170+
}
171+
export -f createGitLog
172+
createGitLog
173+
git submodule foreach 'createGitLog'
174+
else
175+
echo -e "\n\tGit log not generated because a reasonable previous tag could not be found." > $gitLogFile
176+
fi
177+
'''
178+
}
179+
}
180+
}
74181
stage('Create Base builder'){
75182
steps {
76183
dir("${CJE_ROOT}/mbscripts") {
@@ -95,47 +202,6 @@ spec:
95202
}
96203
}
97204
}
98-
stage('Clone Repositories'){
99-
steps {
100-
dir("${CJE_ROOT}/mbscripts") {
101-
sshagent(['github-bot-ssh']) {
102-
sh '''
103-
set -eo pipefail
104-
git config --global user.email '[email protected]'
105-
git config --global user.name 'Eclipse Releng Bot'
106-
./mb100_cloneRepos.sh $CJE_ROOT/buildproperties.shsource 2>&1 | tee $logDir/mb100_cloneRepos.sh.log
107-
'''
108-
}
109-
}
110-
}
111-
}
112-
stage('Tag Build Inputs'){
113-
environment {
114-
ABORT_IF_NO_CHANGES = "${!currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').isEmpty()}" // true, if triggered by timer
115-
}
116-
steps {
117-
dir("${CJE_ROOT}/mbscripts") {
118-
sshagent (['github-bot-ssh', 'projects-storage.eclipse.org-bot-ssh']) {
119-
sh '''
120-
set -xeo pipefail
121-
./mb110_tagBuildInputs.sh $CJE_ROOT/buildproperties.shsource 2>&1 | tee $logDir/mb110_tagBuildInputs.sh.log
122-
'''
123-
}
124-
}
125-
script {
126-
if (env.ABORT_IF_NO_CHANGES && fileExists("${WORKSPACE}/noChanges")) {
127-
emailext subject: "${RELEASE_VER} ${BUILD_TYPE}-Build: ${BUILD_IID} - Build skipped",
128-
body: """\
129-
No changes have been made since the last successful ${BUILD_TYPE}-Build and therefore this scheduled build was skipped:
130-
${BUILD_URL}console
131-
""".stripIndent(), mimeType: 'text/plain',
132-
to: "${BUILD.mailingList}", from: '[email protected]'
133-
currentBuild.result = 'ABORTED'
134-
error('Abort scheduled build due to no changes')
135-
}
136-
}
137-
}
138-
}
139205
stage('Aggregator maven build'){
140206
environment {
141207
KEYRING = credentials('secret-subkeys-releng.asc')

cje-production/buildproperties.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ STREAM="4.38.0"
2323
STREAMMajor="4"
2424
STREAMMinor="38"
2525
STREAMService="0"
26-
GIT_ROOT="[email protected]:"
27-
AGG_REPO="eclipse-platform/eclipse.platform.releng.aggregator.git"
28-
AGG_DIR="gitCache/eclipse.platform.releng.aggregator"
2926
DROP_DIR="siteDir/eclipse/downloads/drops4"
3027
UPDATES_DIR="siteDir/eclipse/updates"
3128
EQUINOX_DROP_DIR="siteDir/equinox/drops"

cje-production/mbscripts/mb100_cloneRepos.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

cje-production/mbscripts/mb110_tagBuildInputs.sh

Lines changed: 0 additions & 101 deletions
This file was deleted.

cje-production/readme.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ This is the location where we will develop production scripts for use on Cloudbe
33
Here are some ground rules
44
1. Each script starts with mb<xxx>_<scriptname>.sh. xxx is a 3 digit number
55
000-099 - preparing build environment like setting environment variables etc.
6-
100-199 - cloning repos and preparing them with right branches/tags and tagging(git operations)
76
200-299 - Maven operations(Updating pom with versions from manifest, create tar ball, build SDK/patch etc)
87
300-399 - gather parts (collecting different artifacts into a temporary build location)
98
500-599 - Generate build reports (running p2.repo.analyzers and dirt report, jdeps reports etc)

0 commit comments

Comments
 (0)