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,300,031
Community Members
 
Community Events
165
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 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
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,255 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you