Skip to content

Instantly share code, notes, and snippets.

@askb
Created November 14, 2017 20:56
Show Gist options
  • Save askb/e72c21c944524b0e5db33e5dbce418cb to your computer and use it in GitHub Desktop.
Save askb/e72c21c944524b0e5db33e5dbce418cb to your computer and use it in GitHub Desktop.
exit: : numeric argument required
#!/bin/bash -x
function bugid_to_jira_task() {
local jira_url="${1}"
local project="${2}"
local bug_id="${3}"
local resp=$(curl -sS --stderr -w {%http_code} --H "Accept: application/json" "${jira_url}/rest/api/2/search\?jql\=project\=${project}%20and%20\\"External%20issue%20ID\\"\~${bug_id}")
echo "$resp"
local issue_id=$(echo "$resp"| jq -r '.issues[].key')
echo "$issue_id"
local status=$(echo "$resp" | awk 'END {print $NF}')
if [ "$status" != "201" ]; then
echo "ERROR: Failed to run. Aborting..."
echo "$resp"
exit "$status"
fi
return $?
}
JIRA_URL="https://jira.opendaylight.org"
buglist=("9228", "2942")
buglist=(${buglist//,/ })
projectlist=("odlparent", "controller")
projectlist=(${projectlist//,/ })
if hash parallel 2>/dev/null; then
export -f bugid_to_jira_task
parallel --verbose -vv --jobs 200% --xapply "bugid_to_jira_task ${JIRA_URL} {1} {2}" ::: ${projectlist[*]} ::: ${buglist[*]}
fi
@askb
Copy link
Author

askb commented Nov 14, 2017

$ ./parallel-test.sh 
+ JIRA_URL=https://jira.opendaylight.org
+ buglist=("9228", "2942")
+ buglist=(${buglist//,/ })
+ projectlist=("odlparent", "controller")
+ projectlist=(${projectlist//,/ })
+ hash parallel
+ export -f bugid_to_jira_task
+ parallel --verbose -vv --jobs 200% --xapply 'bugid_to_jira_task https://jira.opendaylight.org {1} {2}' ::: odlparent ::: 9228
Academic tradition requires you to cite works you base your article on.
When using programs that use GNU Parallel to process data for publication
please cite:

  O. Tange (2011): GNU Parallel - The Command-Line Power Tool,
  ;login: The USENIX Magazine, February 2011:42-47.

This helps funding further development; AND IT WON'T COST YOU A CENT.
If you pay 10000 EUR you should feel free to use GNU Parallel without citing.

To silence the citation notice: run 'parallel --citation'.

bugid_to_jira_task https://jira.opendaylight.org odlparent 9228
bugid_to_jira_task https://jira.opendaylight.org odlparent 9228


ERROR: Failed to run. Aborting...

environment: line 11: exit: : numeric argument required

@askb
Copy link
Author

askb commented Nov 15, 2017

#!/bin/bash

function convert_bugid_to_jira_task() {
    local jira_url="${1}"
    local project="${2}"
    local bug_id="${3}"

    local resp=$(curl -sS -w %{http_code} --header "Accept: application/json" -o /tmp/${project}-${bug_id}.json \
		${jira_url}/rest/api/2/search\?jql\=project\=${project}%20and%20\"External%20issue%20ID\"\~${bug_id})
    #echo "${resp}"
    local issue_id=$(cat /tmp/${project}-${bug_id}.json | jq -r '.issues[].key')
    echo "$issue_id"
    local status=$(echo "$resp" | awk 'END {print $NF}')
    #echo "$status"
    if [ "$status" != "200" ]; then
        echo "ERROR: Failed to run. Aborting..."
        echo "$resp"
        exit "$status"
    fi

    return $?
}

JIRA_URL="https://jira.opendaylight.org"
buglist=("9228" "2942" "9040" "8987" "9060" "9008" "8900" "9145" "9132" "8976")
#buglist=(${buglist//,/ })
projectlist=("odlparent" "controller" "aaa" "bgpcep" "controller" "controller" "gbp" "mdsal" "netconf" "netvirt")
#projectlist=(${projectlist//,/ })

if hash parallel1 2>/dev/null; then
    export -f convert_bugid_to_jira_task
    parallel --no-notice --jobs 200% --xapply "convert_bugid_to_jira_task ${JIRA_URL} {1} {2}" ::: ${projectlist[*]} ::: ${buglist[*]}
else
    length=${#buglist[@]}
    for ((i=0; i<=$length; i++)); do
	if [[ ! -z ${projectlist[$i]} ]] && [[ ! -z ${buglist[$i]} ]]; then
            convert_bugid_to_jira_task "${JIRA_URL}" ${projectlist[$i]} ${buglist[$i]}
        fi
    done
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment