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.