1+ #! /bin/bash
2+
3+ # Check if a profile argument is provided
4+ if [[ -z " $1 " ]]; then
5+ echo " Usage: $0 <aws-profile>"
6+ exit 1
7+ fi
8+
9+ # AWS profile to use for fetching credentials
10+ AWS_PROFILE=" $1 "
11+
12+ # Fetch credentials using AWS SSO and configure
13+ echo " Logging in to AWS SSO..."
14+ aws sso login --profile " $AWS_PROFILE "
15+
16+ # Fetch and export credentials in environment variable format
17+ echo " Fetching temporary AWS credentials..."
18+ credentials=$( aws configure export-credentials --profile " $AWS_PROFILE " --format env-no-export)
19+
20+ if [[ $? -ne 0 ]]; then
21+ echo " Failed to fetch credentials. Please ensure your profile is correctly configured."
22+ exit 1
23+ fi
24+
25+ # Parse and export the credentials as environment variables
26+ eval " $credentials "
27+
28+ # Confirm the variables are set
29+ echo " AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID "
30+ echo " AWS_SECRET_ACCESS_KEY: [hidden]"
31+ echo " AWS_SESSION_TOKEN: [hidden]"
32+
33+ # Optionally, verify with a simple AWS command
34+ aws sts get-caller-identity --profile " $AWS_PROFILE "
35+ if [[ $? -eq 0 ]]; then
36+ echo " AWS authentication successful."
37+ else
38+ echo " AWS authentication failed."
39+ exit 1
40+ fi
41+
42+ # Run Gradle publish task, passing AWS environment variables
43+ echo " Running Gradle publish task..."
44+
45+ # Pass the environment variables to the Gradle process
46+ AWS_ACCESS_KEY_ID=" $AWS_ACCESS_KEY_ID " \
47+ AWS_SECRET_ACCESS_KEY=" $AWS_SECRET_ACCESS_KEY " \
48+ AWS_SESSION_TOKEN=" $AWS_SESSION_TOKEN " \
49+ ./gradlew publish
50+
51+ # Check for success or failure of the gradle publish task
52+ if [[ $? -eq 0 ]]; then
53+ echo " Gradle publish completed successfully."
54+ else
55+ echo " Gradle publish failed."
56+ exit 1
57+ fi
0 commit comments