-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
docker_notify
executable file
·50 lines (41 loc) · 2.44 KB
/
docker_notify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
if [ "$1" == "" ]; then
directory=ref/jobs
else
directory=$1
fi
JENKINS_USERNAME=${JENKINS_USERNAME=:-unspecified-user-name}
JENKINS_APITOKEN=${JENKINS_APITOKEN=:-unspecified-api-token}
tokenarg='&token=insert-our-jenkins-token-here'
# Scan each multi-branch pipeline (URL encode job path before passing as arg to curl
scan_delay=7
git grep -l -F org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject -- $directory | sed -e 's,^ref,,g' -e 's,/jobs/,/job/,g' -e 's,/config.xml$,,g' | shuf | while read multibranch_pipeline
do
scan_delay=$((scan_delay+23))
url_encoded_multibranch_pipeline=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$multibranch_pipeline")
# echo
# echo $multibranch_pipeline to $url_encoded_multibranch_pipeline
# echo http://localhost:8080$url_encoded_multibranch_pipeline?delay=0
echo curl -X POST "http://localhost:8080$url_encoded_multibranch_pipeline/build?delay=${scan_delay}sec"
curl -X POST --user $JENKINS_USERNAME:$JENKINS_APITOKEN "http://localhost:8080$url_encoded_multibranch_pipeline/build?delay=${scan_delay}sec"
# exit 0
done
# Jobs which are disrupted by notifyCommit pushing a specific SHA1 should be executed again
git grep -l -E 'JENKINS-44087|JENKINS-44041|JENKINS-33238|JENKINS-20941' -- $directory | sed -e 's,^ref,,g' -e 's,/jobs/,/job/,g' -e 's,/config.xml$,,g' | shuf | while read build_now_job
do
scan_delay=$((scan_delay+37))
url_encoded_build_now_job=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$build_now_job")
# echo
# echo $build_now_job to $url_encoded_build_now_job
# echo http://localhost:8080$url_encoded_build_now_job?delay=0
echo curl -X POST "http://localhost:8080$url_encoded_build_now_job/build?delay=${scan_delay}sec"
curl -X POST --user $JENKINS_USERNAME:$JENKINS_APITOKEN "http://localhost:8080$url_encoded_build_now_job/build?delay=${scan_delay}sec"
# exit 0
done
# Notify commit each git URL
for url in $(git grep '<url>.*</url>' -- $directory | grep -F config.xml | grep -v JENKINS_HOSTNAME | grep -v JENKINS_ADVERTISED_HOSTNAME | grep -v site/jacoco/index.html | sed -e 's!.*<url>!!g' -e 's!</url>.*$!!g' -e 's!/$!!g' -e 's!.git$!!g' | sort -u | shuf); do
if [[ $url == *"{"* ]]; then
continue
fi
curl -s http://localhost:8080/git/notifyCommit?url=$url$tokenarg
done