Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >./jira -h
- ----------jira options----------
- Required:
- -d [data/issueID]
- -u [username] -> [username] is your JIRA username
- -p [password] -> [password] is your JIRA password
- Optional:
- -q -> quiet, i.e. no output to console
- -h -> help menu
- >./jira -u jsimmons
- ----------jira options----------
- Required:
- -d [data/issueID]
- -u [username] -> [username] is your JIRA username
- -p [password] -> [password] is your JIRA password
- Optional:
- -q -> quiet, i.e. no output to console
- -h -> help menu
- #!/bin/bash
- #using getopts to parse options
- while getopts ":hqd:u:p:" opt; do
- case $opt in
- h)
- help="true"
- ;;
- q)
- quiet="true"
- ;;
- d)
- data=$OPTARG
- ;;
- u)
- username=$OPTARG
- ;;
- p)
- password=$OPTARG
- ;;
- ?)
- echo "Invalid option: -$OPTARG" >&2
- ;;
- :)
- echo "Option -$OPTARG requires an argument." >&2
- ;;
- esac
- done
- #check if required options have been set
- if [[ -n $data && -n $username && -n $password ]]; then
- wget -q --http-user=$username --http-passwd=$password --header="Content-Type: application/json" [URI]
- #placing issue info into variable
- response=$(< $data)
- #using heredoc to run python script
- #python script uses regular expressions to find the value of the field
- #customfield_10701 ie the branch version
- output=$(python - <<EOF
- import re
- matchObj = re.search(r'(?<=customfield_10701":").*(?=","customfield_10702)', '$response', re.I)
- if(matchObj):
- print(matchObj.group())
- EOF
- )
- #writes branch version in .txt file
- echo $output>branchversion.txt
- #prints the branch version if the quiet option hasn't been set
- if [ -z $quiet ]; then
- echo "-------------------------------------------"
- echo ""
- echo "The branch version for issue $data is:"
- cat branchversion.txt
- echo ""
- fi
- #removes file that wget creates containing all data members for the issue
- rm $data
- elif [ -n $help ]; then
- #if help option has been set
- echo ""
- echo "----------jira options----------"
- echo "Required:"
- echo "-d [data/issueID]"
- echo "-u [username] -> [username] is your JIRA username"
- echo "-p [password] -> [password] is your JIRA password"
- echo ""
- echo "Optional:"
- echo "-q -> quiet, i.e. no output to console"
- echo "-h -> help menu"
- echo ""
- #http GET data members for issue
- else
- #if not all required options or help have been set
- echo "Error: Missing argument(s)"
- echo "Usage: ./jira [option(s)] -d [data] -u [username] -p [password]"
- echo ""
- echo "Try: ./jira -h for more options"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement