sys.exit(status)
+@click.command(name='nexus-stage-repo-close')
+@click.argument('nexus-url', envvar='NEXUS_URL')
+@click.argument('staging-profile-id', envvar='STAGING_PROFILE_ID')
+@click.argument('staging-repo-id')
+@click.pass_context
+def nexus_stage_repo_close(ctx, nexus_url, staging_profile_id, staging_repo_id):
+ """Close a Nexus staging repo."""
+ status = subprocess.call([
+ 'deploy', 'nexus-stage-repo-close',
+ nexus_url,
+ staging_profile_id,
+ staging_repo_id
+ ])
+ sys.exit(status)
+
+
+@click.command(name='nexus-stage-repo-create')
+@click.argument('nexus-url', envvar='NEXUS_URL')
+@click.argument('staging-profile-id', envvar='STAGING_PROFILE_ID')
+@click.pass_context
+def nexus_stage_repo_create(ctx, nexus_url, staging_profile_id):
+ """Create a Nexus staging repo."""
+ status = subprocess.call([
+ 'deploy', 'nexus-stage-repo-create',
+ nexus_url,
+ staging_profile_id
+ ])
+ sys.exit(status)
+
+
@click.command(name='nexus-zip')
@click.argument('nexus-url', envvar='NEXUS_URL')
@click.argument('nexus-repo', envvar='NEXUS_REPO')
deploy.add_command(maven_file)
deploy.add_command(nexus)
deploy.add_command(nexus_stage)
+deploy.add_command(nexus_stage_repo_close)
+deploy.add_command(nexus_stage_repo_create)
deploy.add_command(nexus_zip)
deploy_nexus_stage "$@"
exit 0
;;
+ nexus-stage-repo-close )
+ nexus_stage_repo_close "$@"
+ exit 0
+ ;;
+ nexus-stage-repo-create )
+ nexus_stage_repo_create "$@"
+ exit 0
+ ;;
nexus-zip )
echo "Deploying nexus-zip..."
deploy_nexus_zip "$@"
exit 1
fi
- FILE_XML="$(mktemp)"
+ local staging_repo_id
+ staging_repo_id=$(nexus_stage_repo_create "${nexus_url}" "${staging_profile_id}")
+ echo "Staging repository $staging_repo_id created."
+ deploy_nexus "${nexus_url}/service/local/staging/deployByRepositoryId/${staging_repo_id}" "${deploy_dir}"
+
+ nexus_stage_repo_close "${nexus_url}" "${staging_profile_id}" "${staging_repo_id}"
+ echo "Completed uploading files to ${staging_repo_id}."
+}
+
+nexus_stage_repo_close() {
+ # Closes a Nexus staging repo
+ #
+ # Parameters:
+ # nexus_url: URL to Nexus server. (Ex: https://nexus.example.org)
+ # staging_profile_id: The staging profile id as defined in Nexus for the
+ # staging repo.
+ # staging_repo_id: The ID of the repo to close.
+ local nexus_url="${1%/}"
+ local staging_profile_id="$2"
+ local staging_repo_id="$3"
+
+ FILE_XML="$(mktemp)"
cat > "$FILE_XML" <<EOF
<promoteRequest>
<data>
- <description>Create staging repo.</description>
+ <stagedRepositoryId>$staging_repo_id</stagedRepositoryId>
+ <description>Close staging repository.</description>
</data>
</promoteRequest>
EOF
local status
resp=$(curl -s -w " %{http_code}" --netrc -X POST -d "@$FILE_XML" \
-H "Content-Type:application/xml" \
- "${nexus_url}/service/local/staging/profiles/${staging_profile_id}/start")
+ "${nexus_url}/service/local/staging/profiles/${staging_profile_id}/finish")
status=$(echo "$resp" | awk 'END {print $NF}')
+ rm -f "$FILE_XML" # Cleanup
if echo "$resp" | grep -q nexus-error; then
local msg
echo "ERROR: Failed with status code $status"
exit "$status"
fi
+}
- local staging_repo_id
- staging_repo_id=$(sed -n -e 's/.*<stagedRepositoryId>\(.*\)<\/stagedRepositoryId>.*/\1/p' <<< $resp)
- echo "Staging repository $staging_repo_id created."
-
- deploy_nexus "${nexus_url}/service/local/staging/deployByRepositoryId/${staging_repo_id}" "${deploy_dir}"
-
- # Close the repo
+nexus_stage_repo_create() {
+ # Create a Nexus staging repo
+ #
+ # Parameters:
+ # nexus_url: URL to Nexus server. (Ex: https://nexus.example.org)
+ # staging_profile_id: The staging profile id as defined in Nexus for the
+ # staging repo.
+ #
+ # Returns: staging_repo_id
+ local nexus_url="${1%/}"
+ local staging_profile_id="$2"
+ FILE_XML="$(mktemp)"
cat > "$FILE_XML" <<EOF
<promoteRequest>
<data>
- <stagedRepositoryId>$staging_repo_id</stagedRepositoryId>
- <description>Close staging repository.</description>
+ <description>Create staging repo.</description>
</data>
</promoteRequest>
EOF
- curl -s --netrc -X POST \
- -H "Content-Type:application/xml" -d "@$FILE_XML" \
- "${nexus_url}/service/local/staging/profiles/${staging_profile_id}/finish"
+ local resp
+ local status
+ resp=$(curl -s -w " %{http_code}" --netrc -X POST -d "@$FILE_XML" \
+ -H "Content-Type:application/xml" \
+ "${nexus_url}/service/local/staging/profiles/${staging_profile_id}/start")
+ status=$(echo "$resp" | awk 'END {print $NF}')
+ rm -f "$FILE_XML" # Cleanup
- echo "Completed uploading files to ${staging_repo_id}."
+ if echo "$resp" | grep -q nexus-error; then
+ local msg
+ msg=$(sed -n -e 's/.*<msg>\(.*\)<\/msg>.*/\1/p' <<< $resp)
+ echo "ERROR: $msg"
+ exit "$status"
+ elif [ "$status" != "201" ]; then
+ echo "ERROR: Failed with status code $status"
+ exit "$status"
+ fi
- # cleanup
- rm "$FILE_XML"
+ echo "$(sed -n -e 's/.*<stagedRepositoryId>\(.*\)<\/stagedRepositoryId>.*/\1/p' <<< $resp)"
}
deploy_nexus_zip() {