Skip to content

Commit 7a9e08a

Browse files
committed
Add aws ssm fallback
1 parent 3fb4ab9 commit 7a9e08a

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

.gitlab-ci.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ default:
191191
after_script:
192192
- *cgroup_info
193193

194+
# TODO: Add a pre-release check to see if the dd-octo-sts token is working.
194195
# Checks and fail early if central credentials are incorrect, indeed, when a new token is generated
195196
# on the central publisher protal, it invalidates the old one. This checks prevents going further.
196197
# See https://datadoghq.atlassian.net/wiki/x/Oog5OgE
@@ -828,19 +829,39 @@ deploy_artifacts_to_github:
828829
- dd-octo-sts debug --scope DataDog/dd-trace-java --policy self.gitlab.release
829830
- dd-octo-sts token --scope DataDog/dd-trace-java --policy self.gitlab.release > github-token.txt
830831

832+
# TODO: This is a temporary solution to test the dd-octo-sts token during the release process. We should remove the AWS SSM token retrieval method once the dd-octo-sts token is provably working.
831833
script:
832-
- gh auth login --with-token < github-token.txt
833-
- gh auth status # Maybe helpful to have this output in logs?
834-
- export VERSION=${CI_COMMIT_TAG##v} # remove "v" from front of tag to get version
835-
- cp workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar workspace/dd-java-agent/build/libs/dd-java-agent.jar # we upload two filenames
836-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent.jar
837-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar
838-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-api/build/libs/dd-trace-api-${VERSION}.jar
839-
- gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-ot/build/libs/dd-trace-ot-${VERSION}.jar
834+
- |
835+
deploy_to_github() {
836+
gh auth login --with-token < github-token.txt
837+
gh auth status
838+
export VERSION=${CI_COMMIT_TAG##v} # remove "v" from front of tag to get the version
839+
cp workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar workspace/dd-java-agent/build/libs/dd-java-agent.jar # upload two filenames
840+
gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent.jar
841+
gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-java-agent/build/libs/dd-java-agent-${VERSION}.jar
842+
gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-api/build/libs/dd-trace-api-${VERSION}.jar
843+
gh release upload --clobber --repo DataDog/dd-trace-java $CI_COMMIT_TAG workspace/dd-trace-ot/build/libs/dd-trace-ot-${VERSION}.jar
844+
}
845+
846+
# Try using the dd-octo-sts token first. If it fails, then fall back to the AWS SSM token.
847+
# Also track which token was used successfully.
848+
if ! deploy_to_github; then
849+
echo "Using dd-octo-sts token failed. Now proceeding with the original AWS SSM token retrieval method..."
850+
echo "USED_DD_OCTO_STS_TOKEN=false" > github_token_source.env
851+
aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.gh_release_token --with-decryption --query "Parameter.Value" --out text > github-token.txt
852+
deploy_to_github
853+
else
854+
echo "Using dd-octo-sts token succeeded. Github release artifacts were uploaded successfully."
855+
echo "USED_DD_OCTO_STS_TOKEN=true" > github_token_source.env
856+
fi
840857
841858
after_script:
842-
# Revoke the token after usage
843-
- dd-octo-sts revoke -t $(cat github-token.txt)
859+
# Only revoke the dd-octo-sts token if it was successfully used
860+
- source github_token_source.env
861+
- |
862+
if [ "$USED_DD_OCTO_STS_TOKEN" = "true" ]; then
863+
dd-octo-sts revoke -t $(cat github-token.txt)
864+
fi
844865
845866
retry:
846867
max: 2

0 commit comments

Comments
 (0)