mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-16 02:38:44 +00:00
104 lines
3.5 KiB
Bash
Executable File
104 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
||
if [ $# -eq 0 ]; then
|
||
echo "$0 <bugid>"
|
||
echo ""
|
||
echo
|
||
echo "Constructs a Jenkins job for the given issue ID"
|
||
echo "Example: $0 4221 [ {Bugzilla-API-Key} ]"
|
||
echo "Builds a Jenkins job for bug branch bug4221, and linking to the Github Issue."
|
||
exit 2
|
||
fi
|
||
|
||
BUG_ID="$1"
|
||
|
||
CONFIGFILE=$(mktemp mylocalconfigXXXX.xml)
|
||
RESPONSE_HEADERS=$(mktemp responseheadersXXXX)
|
||
JENKINS_BASE_URL=https://ci.eclipse.org/sailing-analytics
|
||
GITHUB_ISSUES_BASE="https://github.com/eclipse-sailing-analytics/sailing-analytics/issues/"
|
||
BUGZILLA_BASE=https://bugzilla.sapsailing.com/bugzilla
|
||
COPY_TEMPLATE_JOB=CopyTemplate
|
||
OS_FOR_GSED="darwin"
|
||
echo "Trying to obtain bug summary/title from Github..."
|
||
BUG_SUMMARY="$( curl -s -H 'Accept: application/vnd.github+json' https://api.github.com/repos/eclipse-sailing-analytics/sailing-analytics/issues/${BUG_ID} | jq -r '.title' )"
|
||
echo "Found: ${BUG_SUMMARY}"
|
||
if [ -z "${USERNAME}" ]; then
|
||
if [[ "$OSTYPE" == *"$OS_FOR_GSED"* ]]; then
|
||
read -e -p "Jenkins Username (e-mail): " USERNAME
|
||
else
|
||
read -p "Jenkins Username (e-mail): " USERNAME
|
||
fi
|
||
fi
|
||
if [ -z "${PASSWORD}" ]; then
|
||
read -s -p "Jenkins Password (API Token): " PASSWORD
|
||
fi
|
||
echo
|
||
COPY_TEMPLATE_CONFIG_URL="$JENKINS_BASE_URL/job/$COPY_TEMPLATE_JOB/config.xml"
|
||
curl -s -X GET $COPY_TEMPLATE_CONFIG_URL -u "$USERNAME:$PASSWORD" -o "$CONFIGFILE"
|
||
|
||
# On macosx is gnu-sed needed
|
||
if [[ "$OSTYPE" == *"$OS_FOR_GSED"* ]]; then
|
||
echo "Using gsed"
|
||
gsed -i'' -e 's|<description>..*</description>|<description>This is the CI job for \<a href=\"'${GITHUB_ISSUES_BASE}${BUG_ID}'\"\>Bug '$BUG_ID'\</a\> ('"${BUG_SUMMARY}"'). See its latest \<a href=\"/userContent/measurements.html?job=bug'$BUG_ID'\"\>quality and performance measurements here.\</a\></description>|' -e 's|<disabled>true</disabled>|<disabled>false</disabled>|' "$CONFIGFILE"
|
||
else
|
||
sed -i -e 's|<description>..*</description>|<description>This is the CI job for \<a href=\"'${GITHUB_ISSUES_BASE}${BUG_ID}'\"\>Bug '$BUG_ID'\</a\> ('"${BUG_SUMMARY}"'). See its latest \<a href=\"/userContent/measurements.html?job=bug'$BUG_ID'\"\>quality and performance measurements here.\</a\></description>|' -e 's|<disabled>true</disabled>|<disabled>false</disabled>|' "$CONFIGFILE"
|
||
fi
|
||
|
||
# On macosx is gnu-sed needed
|
||
if [[ "$OSTYPE" == *"$OS_FOR_GSED"* ]]; then
|
||
echo "Using gsed"
|
||
gsed -i'' -n -e ':loop
|
||
/<command>/b InCommand
|
||
p
|
||
$b
|
||
N
|
||
D
|
||
b loop
|
||
:InCommand
|
||
s/BRANCH/'bug${BUG_ID}'/g
|
||
/<\/command>/p
|
||
/<\/command>/b End
|
||
N
|
||
b InCommand
|
||
:End
|
||
' "$CONFIGFILE"
|
||
else
|
||
sed -i -n -e ':loop
|
||
/<command>/b InCommand
|
||
p
|
||
$b
|
||
N
|
||
D
|
||
b loop
|
||
:InCommand
|
||
s/BRANCH/'bug${BUG_ID}'/g
|
||
/<\/command>/p
|
||
/<\/command>/b End
|
||
N
|
||
b InCommand
|
||
:End
|
||
' "$CONFIGFILE"
|
||
fi
|
||
|
||
if [[ "$OSTYPE" == *"$OS_FOR_GSED"* ]]; then
|
||
gsed -i'' -e '/<branches>$/{
|
||
N
|
||
N
|
||
s|<name>[^<]*</name>|<name>bug'$BUG_ID'</name>|
|
||
}' "$CONFIGFILE"
|
||
else
|
||
sed -i -e '/<branches>$/{
|
||
N
|
||
N
|
||
s|<name>[^<]*</name>|<name>bug'$BUG_ID'</name>|
|
||
}' "$CONFIGFILE"
|
||
fi
|
||
curl -D "$RESPONSE_HEADERS" -s -XPOST "$JENKINS_BASE_URL/createItem?name=bug$BUG_ID" -u "$USERNAME:$PASSWORD" --data-binary "@$CONFIGFILE" -H "Content-Type:text/xml" >/dev/null 2>/dev/null
|
||
RESPONSE_CODE=$(cat "$RESPONSE_HEADERS" | head -n 1 | cut -d ' ' -f2 )
|
||
if [[ "$RESPONSE_CODE" =~ 2.. ]]; then
|
||
echo "Find your new, enabled Jenkins job at $JENKINS_BASE_URL/job/bug$BUG_ID/"
|
||
else
|
||
echo "Error. HTTP response code $RESPONSE_CODE. Did the job already exist?"
|
||
fi
|
||
rm "$CONFIGFILE"
|
||
rm "$RESPONSE_HEADERS"
|