diff --git a/assets/out b/assets/out index 5190e6f..0427716 100755 --- a/assets/out +++ b/assets/out @@ -12,60 +12,59 @@ payload=$(mktemp /tmp/resource.XXXXXX) cat > "${payload}" <&0 # source -bitbucket_type=`jq -r '.source.bitbucket_type // "server"' < ${payload}` -base_url=`jq -r '.source.base_url // ""' < ${payload}` -username=`jq -r '.source.username // ""' < ${payload}` -password=`jq -r '.source.password // ""' < ${payload}` -project=`jq -r '.source.project // ""' < ${payload}` -repository=`jq -r '.source.repository // ""' < ${payload}` -dir=`jq -r '.source.dir // ""' < ${payload}` +bitbucket_type=$(jq -r '.source.bitbucket_type // "server"' < "${payload}") +base_url=$(jq -r '.source.base_url // ""' < "${payload}") +username=$(jq -r '.source.username // ""' < "${payload}") +password=$(jq -r '.source.password // ""' < "${payload}") +project=$(jq -r '.source.project // ""' < "${payload}") +repository=$(jq -r '.source.repository // ""' < "${payload}") +dir=$(jq -r '.source.dir // ""' < "${payload}") if [[ ! ${dir} ]]; then dir=$repository fi # params -build=`jq '.params' < ${payload}` +build=$(jq '.params' < "${payload}") -if [[ ! ${base_url} ]]; then +if [[ ! "${base_url}" ]]; then echo "error: source.base_url can't be empty" exit 1 fi -cd ${dir} +cd "${dir}" -pr=`cat pull-request-info` -commit=`echo ${pr} | jq -r '.commit'` +pr=$(cat pull-request-info) +commit=$(echo "${pr}" | jq -r '.commit') build_url="${ATC_EXTERNAL_URL}/builds/${BUILD_ID}" -if [[ "$bitbucket_type" == "server" ]]; then +if [[ "${bitbucket_type}" == "server" ]]; then url="${base_url}/rest/build-status/1.0/commits/${commit}" - json=`echo "${build}" | jq --arg build_url "${build_url}" --arg id "${BUILD_ID}" '{ + json=$(echo "${build}" | jq --arg build_url "${build_url}" --arg id "${BUILD_ID}" '{ state: .state, key: .key, name: (.key + "-" + $id), url: $build_url, description: .description|tostring - }'` + }') elif [[ "$bitbucket_type" == "cloud" ]]; then url="${base_url}/api/2.0/repositories/${project}/${repository}/commit/${commit}/statuses/build" - # expand variables like $BUILD_ID before passing into JSON name=$(echo "$build"| jq -r '.name') - name=$(eval echo $name) + name=$(eval echo "$name") desc=$(echo "$build"| jq -r '.description') - desc=$(eval echo $desc) + desc=$(eval echo "$desc") build_url=$(echo "$build"| jq -r '.url') - build_url=$(eval echo $build_url) - json=`echo "${build}" | jq --arg build_url "${build_url}" --arg id "${BUILD_ID}" --arg name "$name" --arg desc "$desc" '{ + build_url=$(eval echo "$build_url") + json=$(echo "${build}" | jq --arg build_url "${build_url}" --arg id "${BUILD_ID}" --arg name "${name}" --arg desc "${desc}" '{ state: .state, key: $name, name: ($name + "-" + $id), url: $build_url, description: $desc - }'` + }') fi -curl -s --fail -u ${username}:${password} -H "Content-Type: application/json" -XPOST ${url} -d "${json}" +curl -s --fail -u "${username}:${password}" -H "Content-Type: application/json" -XPOST "${url}" -d "${json}" jq -n --argjson pr "${pr}" --argjson pr "${pr}" '{ version: {