I have this bitbucket pipeline:
image: ubuntu:latest
pipelines:
branches:
master:
- step:
name: Upload
script:
- apt-get update && apt-get install -y openssh-client jq curl
- cat /opt/atlassian/pipelines/agent/ssh/id_rsa >> ec2_private_key.pem
- chmod 600 ec2_private_key.pem
- echo "Fetching modified files from Bitbucket API using diff endpoint"
- |
curl -s -H "Authorization: Bearer $API_TOKEN_BEARER" \
"https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_FULL_NAME/commits/master" \
| jq -r '.values[0].hash' > latest_commit.txt
- COMMIT_HASH=$(cat latest_commit.txt)
- |
curl -s -H "Authorization: Bearer $API_TOKEN_BEARER" \
"https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_FULL_NAME/diff/$COMMIT_HASH" \
| grep '^+++ b' | awk '{print $2}' | sed 's/^b\///' > modified_files.txt
- echo "Modified files:"
- cat modified_files.txt
- while IFS= read -r file; do
scp -i ec2_private_key.pem -o StrictHostKeyChecking=no -r "$file" ubuntu@$EC2_HOST:$PATH"$file";
done < modified_files.txt
- ssh -i ec2_private_key.pem -o StrictHostKeyChecking=no ubuntu@$EC2_HOST "cd $PATH && sudo docker-compose up --build -d"
Which is very similar to another pipeline I have in another repository and already works. However, it seems that the image is not correctly installed when the pipeline is executed. In the build set up, I get this error:
Images used: build : docker.io/library/ubuntu@sha256: bash: dircolors: command not found
And in the apt-get line I get this error:
- apt-get update && apt-get install -y openssh-client jq curl bash: apt-get: command not found
The problem was that PATH cannot be declared as a repository variable, since it is a reserved word, so I needed to change the name of the variable and now the pipeline correctly installs the image, so that it can be run properly.