Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. >./jira -h
  2.  
  3. ----------jira options----------
  4. Required:
  5. -d [data/issueID]
  6. -u [username] -> [username] is your JIRA username
  7. -p [password] -> [password] is your JIRA password
  8.  
  9. Optional:
  10. -q -> quiet, i.e. no output to console
  11. -h -> help menu
  12.  
  13. >./jira -u jsimmons
  14.  
  15. ----------jira options----------
  16. Required:
  17. -d [data/issueID]
  18. -u [username] -> [username] is your JIRA username
  19. -p [password] -> [password] is your JIRA password
  20.  
  21. Optional:
  22. -q -> quiet, i.e. no output to console
  23. -h -> help menu
  24.  
  25. #!/bin/bash
  26.  
  27. #using getopts to parse options
  28. while getopts ":hqd:u:p:" opt; do
  29. case $opt in
  30. h)
  31. help="true"
  32. ;;
  33. q)
  34. quiet="true"
  35. ;;
  36. d)
  37. data=$OPTARG
  38. ;;
  39. u)
  40. username=$OPTARG
  41. ;;
  42. p)
  43. password=$OPTARG
  44. ;;
  45. ?)
  46. echo "Invalid option: -$OPTARG" >&2
  47. ;;
  48. :)
  49. echo "Option -$OPTARG requires an argument." >&2
  50. ;;
  51. esac
  52. done
  53.  
  54. #check if required options have been set
  55. if [[ -n $data && -n $username && -n $password ]]; then
  56.  
  57. wget -q --http-user=$username --http-passwd=$password --header="Content-Type: application/json" [URI]
  58.  
  59.  
  60. #placing issue info into variable
  61.  
  62. response=$(< $data)
  63.  
  64.  
  65. #using heredoc to run python script
  66. #python script uses regular expressions to find the value of the field
  67. #customfield_10701 ie the branch version
  68.  
  69. output=$(python - <<EOF
  70. import re
  71.  
  72. matchObj = re.search(r'(?<=customfield_10701":").*(?=","customfield_10702)', '$response', re.I)
  73. if(matchObj):
  74. print(matchObj.group())
  75.  
  76. EOF
  77. )
  78.  
  79.  
  80. #writes branch version in .txt file
  81.  
  82. echo $output>branchversion.txt
  83.  
  84.  
  85. #prints the branch version if the quiet option hasn't been set
  86. if [ -z $quiet ]; then
  87. echo "-------------------------------------------"
  88. echo ""
  89. echo "The branch version for issue $data is:"
  90. cat branchversion.txt
  91. echo ""
  92. fi
  93.  
  94. #removes file that wget creates containing all data members for the issue
  95.  
  96. rm $data
  97. elif [ -n $help ]; then
  98. #if help option has been set
  99. echo ""
  100. echo "----------jira options----------"
  101. echo "Required:"
  102. echo "-d [data/issueID]"
  103. echo "-u [username] -> [username] is your JIRA username"
  104. echo "-p [password] -> [password] is your JIRA password"
  105. echo ""
  106. echo "Optional:"
  107. echo "-q -> quiet, i.e. no output to console"
  108. echo "-h -> help menu"
  109. echo ""
  110. #http GET data members for issue
  111. else
  112. #if not all required options or help have been set
  113. echo "Error: Missing argument(s)"
  114. echo "Usage: ./jira [option(s)] -d [data] -u [username] -p [password]"
  115. echo ""
  116. echo "Try: ./jira -h for more options"
  117. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement