Skip to content

Commit

Permalink
fix ShellScript issues
Browse files Browse the repository at this point in the history
  • Loading branch information
idr0id committed Jan 28, 2019
1 parent ca9c58c commit fd990ac
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit fd990ac

Please sign in to comment.