Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,535
Community Members
 
Community Events
184
Community Groups

Export Code Artifact Token in pipeline and use it to download dependency in Maven project

I have a pipeline for a Maven project, which contains 2 modules in it. In one of the modules, there is a dependency for a remote project, which can be pulled as a code artifact. The problem is that when i generate a token for AWS, to authenticate the for the download from the remote repository, the module which needs to pull the code artifact doesn't get authorization to download it. I get 401 unauthorized when whe pom.xml file tries to pull the dependency

pipelines:
default:
- step:
name: Build and Test
script:
- yum install sudo -y
- yum install zip unzip -y
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- sudo ./aws/install
- aws configure set aws_access_key_id $ACCESS_KEY
- aws configure set aws_secret_access_key $SECRET_ACCESS_KEY
- aws configure set profile.$PROFILE_NAME.source_profile default
- aws configure set profile.$PROFILE_NAME.region $AWS_REGION
- aws configure set profile.$PROFILE_NAME.role_arn $PROFILE_ARN
- export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain $DOMAIN --domain-owner $DOMAIN_OWNER --query authorizationToken --output text --profile $PROFILE_NAME`
- echo $CODEARTIFACT_AUTH_TOKEN
- sed -i 's/${env.CODEARTIFACT_AUTH_TOKEN}/'"$CODEARTIFACT_AUTH_TOKEN"'/g' $MODULE_PATH/settings.xml
- cat $MODULE_PATH/settings.xml
- mvn clean deploy -s $MODULE_PATH/pom.xml -P snapshot
- mvn verify --file pom.xml

Currently I'm writing using the 'sed' command to write the password directly in settings.xml, because I wasn't sure if it was being exported properly, but it doesn't work either way. From the 'cat' command i can verify that the token is actually written in the settings.xml file. Note that the only environment variable im using in the original pipeline is the $CODEARTIFACT_AUTH_TOKEN. I'm just using variables for everything here to not show sensitive data.

1 answer

1 accepted

0 votes
Answer accepted
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Feb 16, 2022

Hi @Tasho Georgiev

Welcome to the community.

Just wanted to confirm if the settings.xml file is located under the location "/usr/share/maven/conf"?
This is because you'll need to override the default Maven settings.xml found in the Docker image.

To access a private Maven repository, you'll need to override the default Maven settings.xml found in the Docker image at /usr/share/maven/conf/settings.xml.

Alternatively, you can also override the file by using your own version of the settings.xml file using the command below:

mvn -s settings.xml

You can also check out this link for more information.

Let me know how it goes.

Regards,
Mark C

Hi @Mark C , since posting the question, I was able to resolve the problem. It was indeed missing the settings.xml file. After adding it to the project the issue was resolved.

Still, thank you for the reply!

Like Mark C likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events