From e248578a99b7a855de00e1c71982ed1a734e7e16 Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Tue, 28 Jun 2022 19:52:02 +0100 Subject: [PATCH] added jenkins_cred_create2_user_pass.sh --- jenkins_cred_create2_user_pass.sh | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 jenkins_cred_create2_user_pass.sh diff --git a/jenkins_cred_create2_user_pass.sh b/jenkins_cred_create2_user_pass.sh new file mode 100755 index 00000000..a4cbf145 --- /dev/null +++ b/jenkins_cred_create2_user_pass.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# vim:ts=4:sts=4:sw=4:et +# args: haritest-cli-credential hari mypassword +# +# Author: Hari Sekhon +# Date: 2022-06-28 18:34:34 +0100 (Tue, 28 Jun 2022) +# +# https://github.com/HariSekhon/DevOps-Bash-tools +# +# License: see accompanying Hari Sekhon LICENSE file +# +# 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 +# +# https://www.linkedin.com/in/HariSekhon +# + +set -euo pipefail +[ -n "${DEBUG:-}" ] && set -x +srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# shellcheck disable=SC1090 +. "$srcdir/lib/utils.sh" + +# shellcheck disable=SC2034,SC2154 +usage_description=" +Creates a Jenkins credential in the given credential store and domain + +Defaults to the 'system::system::jenkins' provider store and global domain '_' + +Uses the adjacent jenkins_li.sh - see there for authentication details +" + +# used by usage() in lib/utils.sh +# shellcheck disable=SC2034 +usage_args="[ ]" + +help_usage "$@" + +id="${1:-}" +user="${2:-}" +password="${3:-}" +store="${4:-system::system::jenkins}" +domain="${5:-_}" +description="${6:-}" + +create_credential(){ + local id="$1" + local user="$2" + local password="$3" + xml=" + GLOBAL + $id + $description + $user + $password + false +" + echo "$xml" + set -x + "$srcdir/jenkins_cli.sh" create-credentials-by-xml "$store" "$domain" <<< "$xml" +} + +if [ -n "$password" ]; then + create_credential "$id" "$user" "$password" +else + # XXX: switch this to accepting standard 'export KEY=VALUE' format for pipe chaining with other tools + while read -r id user password; do + [ -n "$password" ] || continue + create_credential "$id" "$user" "$password" + done +fi