-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutler-jenkins-export-import.sh
More file actions
executable file
·64 lines (55 loc) · 2.08 KB
/
butler-jenkins-export-import.sh
File metadata and controls
executable file
·64 lines (55 loc) · 2.08 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# butler-jenkins-export-import.sh - Use Butlet to export and import jobs and credentials for Jenkins servers
set -e -o pipefail -u
if [ ! -e butler ] ; then
wget https://s3.us-east-1.amazonaws.com/butlercli/1.0.0/linux/butler
chmod 755 butler
fi
export PATH="$PATH:`pwd`"
_butler_export () {
# Get the plugins list
butler plugins export --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" \
| cut -d '|' -f 2,3 | tr -d ' ' | grep '^[a-zA-Z]' | sort | sed -e 's/|/:/' > plugins.txt
# Get the jobs and credentials
butler jobs export --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW"
butler credentials decrypt --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" -f "." > decryptedCredentials.json
(
cd jobs
for d in * ; do
(
cd "$d"
butler jobs export --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" -f "$d"
butler credentials decrypt --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" -f "$d" > decryptedCredentials.json
)
done
)
}
_butler_import () {
# Get the plugins list
butler plugins import --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" < plugins.txt
# Get the jobs and credentials
butler jobs import --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW"
butler credentials apply --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" -f "." < decryptedCredentials.json
(
cd jobs
for d in * ; do
(
cd "$d"
butler jobs import --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" -f "$d"
butler credentials apply --server "$JENKINS_URL" -u "$JENKINS_USR" -p "$JENKINS_PSW" -f "$d" < decryptedCredentials.json
)
done
)
}
if [ $# -lt 1 ] ; then
echo "Usage: $0 CMD"
echo ""
echo "Commands:"
echo " export"
echo " import"
exit 1
elif [ "$1" = "export" ] ; then
_butler_export
elif [ "$1" = "import" ] ; then
_butler_import
fi