@@ -19,39 +19,65 @@ jira_project_template_key="$3"
1919[[ ${4:- } == " " ]] && echo " Please parse the project lead to create from as parameter 4"
2020jira_project_lead=" $4 "
2121
22- jira_project_lead=$( whoami | awk -F' \' ' {print $2}' )
22+ if [[ ${create_mode:- } == " " ]]; then
23+ create_mode=" skipOcreate" # deleteNcreate , skipNcreate(default), delete
24+ echo " Using default mode: $create_mode - Options: deleteNcreate , skipOcreate(default), delete"
25+ else
26+ echo " Using create_mode: $create_mode - Options: deleteNcreate , skipOcreate(default), delete"
27+ fi
2328
2429netrc_file=~ /.netrc
2530
2631curl_GET_cmd=" curl --fail --insecure --netrc-file ${netrc_file} -X GET -H Content-Type:application/json -o - "
2732curl_POST_cmd=" curl --fail --insecure --netrc-file ${netrc_file} -X POST -H Content-Type:application/json -o - "
2833curl_DELETE_cmd=" curl --fail --insecure --netrc-file ${netrc_file} -X DELETE -H Content-Type:application/json -o - "
2934
35+ project_key_found=$( ${curl_GET_cmd} --silent --url " ${jira_server} /rest/api/2/project/${jira_project_new_key} " | jq -r .key )
36+
37+ if [[ $create_mode == " delete" ]]; then
38+ if [[ " ${project_key_found} " == " ${jira_project_new_key} " ]] ; then
39+ printf " Project found: $project_key_found - delete it... and it might take some time depend on the amount of issues.."
40+ printf " - but sleep for 10 sec to offer abort...\n"
41+ sleep 10
42+ ${curl_DELETE_cmd} --url ${jira_server} /rest/api/2/project/${jira_project_new_key}
43+ exit 0
44+ else
45+ echo " Project not found: $jira_project_new_key - skip deleting"
46+ exit 0
47+ fi
48+ fi
49+
3050project_template_id=$( ${curl_GET_cmd} --silent --url ${jira_server} /rest/api/2/project/${jira_project_template_key} | jq -r .id )
3151if [[ ${project_template_id} == " " ]] ; then
3252 echo " Template project: $jira_project_template_key NOT found on server: $jira_server "
3353 exit 1
34- else
35- echo " Using project: $jira_project_template_key as template on $jira_server "
3654fi
3755
38- project_key_found=$( ${curl_GET_cmd} --silent --url " ${jira_server} /rest/api/2/project/${jira_project_new_key} " | jq -r .key )
3956if [[ " ${project_key_found} " == " ${jira_project_new_key} " ]] ; then
40- printf " Project found: $project_key_found - delete it first... and it might take some depend on the amount of issues.."
41- if [[ ${force:- } == true ]] ; then
42- printf " - run in force mode without sleeping\n"
43- else
44- printf " - but sleep for 10 sec to offer abort...\n"
45- sleep 10
57+ if [[ $create_mode == " deleteNcreate" ]]; then
58+ printf " Project found: $project_key_found - delete it first... and it might take some depend on the amount of issues.."
59+ if [[ ${force:- } == true ]] ; then
60+ printf " - run in force mode without sleeping\n"
61+ else
62+ printf " - but sleep for 10 sec to offer abort...\n"
63+ sleep 10
64+ fi
65+ echo " .. starting .."
66+ ${curl_DELETE_cmd} --url ${jira_server} /rest/api/2/project/${jira_project_new_key}
67+ fi
68+ if [[ $create_mode == " skipOcreate" ]]; then
69+ echo " Project found: $project_key_found - skip"
70+ exit 0
4671 fi
47- echo " .. starting .."
48- ${curl_DELETE_cmd} --url ${jira_server} /rest/api/2/project/${jira_project_new_key}
4972else
50- echo " Project: $jira_project_new_key not found on server: $jira_server "
73+ echo " Project: $jira_project_new_key not found on server: $jira_server - create it "
5174fi
5275
76+ echo " Using project: $jira_project_template_key as template on $jira_server "
77+
5378echo " Create new project key:$jira_project_new_key name:\" $jira_project_new_name \" from $jira_project_template_key "
5479$curl_POST_cmd -d " { \" key\" :\" ${jira_project_new_key} \" , \" name\" :\" ${jira_project_new_name} \" ,\" lead\" :\" $jira_project_lead \" }" \
5580 --url ${jira_server} /rest/project-templates/1.0/createshared/${project_template_id}
81+ echo
5682
57- # curl -D- -u <username>:<password> -H "Content-Type:application/json" -X POST -d '{"user":["username"]}' -k https://jira-stg.example.com/rest/api/2/project/ABC/role/10002
83+ # curl -D- -u <username>:<password> -H "Content-Type:application/json" -X POST -d '{"user":["username"]}' -k https://jira-stg.example.com/rest/api/2/project/ABC/role/10002
0 commit comments