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

Why is the dynamic variable not working in my command?

Falco April 19, 2021

Hi,

My script works fine when for example the variable 

$ZIP_FILE_NAME in - zip -r $ZIP_FILE_NAME . -x *.git*

is written static like:

- zip -r demo.zip . -x *.git*

However, when I try to use via call to a dynamic variable defined in the global variables of the repository. I have this error in the pipeline: 

The user-provided path demo.zip does not exist.

Can you help? here the script I use:

image: node:6.9.4
pipelines:
default:
-
step:
name: "Zip the code"
script:
-
AWS_ZIP_FILE_DSN_NAME="demo"
-
echo "zip file"
-
apt-get update && apt-get install zip --assume-yes
-
zip -r $ZIP_FILE_NAME . -x *.git*
artifacts: - $ZIP_FILE_NAME
-
step: name: "Push the zip file to S3"
caches: - node
script: - echo "push to s3 bucket"
# install Amazon CLI
-
apt-get update
-
apt-get install -y python --assume-yes
-
apt-get install -y jq
-
curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
-
python get-pip.py - python -m pip install --upgrade "pip < 21.0"
-
pip install awscli - aws configure set default.region eu-west-1
-
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile $AWS_PROFILE_NAME
-
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile $AWS_PROFILE_NAME
-
aws iam get-user - temp_role=$(aws sts assume-role --role-arn $AWS_ROLE_ARN --role-session-name "assumedrole" --profile $AWS_PROFILE_NAME)
-
aws configure set aws_access_key_id $(echo $temp_role | jq .Credentials.AccessKeyId | xargs) --profile $AWS_PROFILE_NAME
-
aws configure set aws_secret_access_key $(echo $temp_role | jq .Credentials.SecretAccessKey | xargs) --profile $AWS_PROFILE_NAME
-
aws configure set aws_session_token $(echo $temp_role | jq .Credentials.SessionToken | xargs) --profile $AWS_PROFILE_NAME
-
aws s3 cp "./$ZIP_FILE_NAME" $AWS_S3_BUCKET --profile $AWS_PROFILE_NAME

 

The error is generated for 

- aws s3 cp "./$ZIP_FILE_NAME" $AWS_S3_BUCKET --profile $AWS_PROFILE_NAME

 

Thanks a lot on advance

Aude F

1 answer

1 accepted

0 votes
Answer accepted
Falco April 21, 2021

Hi finally managed to have it work. The problem came from the artifacts. They cannot be set with dynamic variables. Code works OK otherwise. May need a few updates.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events