Skip to content

Commit e594c70

Browse files
committed
added jenkins_jobs_enable.sh
1 parent e50fbab commit e594c70

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

jenkins/jenkins_jobs_enable.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
# vim:ts=4:sts=4:sw=4:et
3+
#
4+
# Author: Hari Sekhon
5+
# Date: 2024-02-23 01:13:35 +0000 (Fri, 23 Feb 2024)
6+
#
7+
# https://github.com/HariSekhon/DevOps-Bash-tools
8+
#
9+
# License: see accompanying Hari Sekhon LICENSE file
10+
#
11+
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
12+
#
13+
# https://www.linkedin.com/in/HariSekhon
14+
#
15+
16+
# https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
17+
18+
set -euo pipefail
19+
[ -n "${DEBUG:-}" ] && set -x
20+
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21+
22+
# shellcheck disable=SC1090,SC1091
23+
. "$srcdir/lib/utils.sh"
24+
25+
# shellcheck disable=SC2034,SC2154
26+
usage_description="
27+
Enables all Jenkins jobs/pipelines with names matching a given regex via the Jenkins API
28+
29+
Tested on Jenkins 2.319 and 2.246
30+
31+
Remember to quote the job name regex filter to stop it matching your local files eg. '.*' to not match '. .. .envrc'
32+
33+
Uses the adjacent jenkins_job_enable.sh jenkins_api.sh - see there for authentication details
34+
"
35+
36+
# used by usage() in lib/utils.sh
37+
# shellcheck disable=SC2034
38+
usage_args="<job_name_regex_filter> [<curl_options>]"
39+
40+
help_usage "$@"
41+
42+
min_args 1 "$@"
43+
44+
if [[ "$*" =~ \.\ \.\. ]]; then
45+
die "You've specified an unquoted .* that has match . and .. directories - remember to quote your regex!"
46+
fi
47+
48+
job_name_regex_filter="$1"
49+
shift || :
50+
51+
timestamp "Getting job list"
52+
"$srcdir/jenkins_jobs.sh" "$@" |
53+
while read -r job_name; do
54+
if [[ "$job_name" =~ $job_name_regex_filter ]]; then
55+
"$srcdir/jenkins_job_enable.sh" "$job_name" "$@"
56+
fi
57+
done

0 commit comments

Comments
 (0)