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,456,333
Community Members
 
Community Events
176
Community Groups

Updating $PATH while running a bitbucket pipeline

I'm working with hashicorp/terraform:latest image (which is very minimal) and need to install go. After installing go into /usr/local. As a next step we need to update $PATH so that we could run go commands. But the export PATH does not take and the shell can't find go executable which is in /usr/local/go/bin.

We can't quite figure out how to go about this. Help is greatly appreciated!

```

image: hashicorp/terraform:latest
pipelines:
branches:
dev:
- step:
name: Build & deploy [dev]
# image: golang
deployment: Dev
script:
- apk add bash
- apk add zip
- source bitbucket-pipelines.sh
- cd ${IMPORT_PATH}
# Install go
- tar -C /usr/local -xzf go1.17.2.linux-amd64.tar.gz
- ls -la /usr/local/go/bin
- export PATH=$PATH:/usr/local/go/bin
- echo $PATH
- echo $0 # show shell exec
- go version # this fails with file not found

```

2 answers

0 votes

Hi @Misha _HS_,

I have tried to reproduce this locally by running a Docker container with the image you are using:

docker run -it --entrypoint=/bin/sh hashicorp/terraform:latest

and then I executed the commands you have in your yml file (apart from lines 3 and 4 of the script)

The command go version also fails when debugging this locally.

If I try the installation in a different Docker container, e.g. atlassian/default-image:3 which is based on Ubuntu, the installation of go seems to succeed (both locally and in Pipelines).

It is possible that the file you are downloading is not the correct one for Alpine Linux or extra/different steps may be needed for the installation in Alpine. I'm afraid I don't know what exactly is causing the problem here, but it seems to be specific to the Linux distribution of the Docker image.

Kind regards,
Theodora

Oh, great, thank you Theodora. I will play with the image. It looks like Alpine does not like the compiled for amd64 go binary. I will update this ticket with what I find.

Like Theodora Boudale likes this

Pre-compiled go binary seems not to be compatible with alpine.

You can see an example of how to build go from source on alpine at this dockerfile
https://github.com/docker-library/golang/blob/67757c0feeb9867a54801ca378dcfc55b9db7e70/1.17/alpine3.15/Dockerfile

 

Better option would be as suggested already by Atlassian team to use another image based on Debian / Ubuntu

Regards

Like Theodora Boudale likes this

Thanks for posting that example Jack!

@Misha _HS_, I also found the following blog post, the solution suggested there is to install go with apk:

Kind regards,
Theodora

0 votes

Hi there maybe you must add execution permissions to go binary?

chmod a+x /usr/local/go/bin/go

What I'm getting is file not found (not a permission issue)

/opt/atlassian/pipelines/agent/tmp/shellScript5553201990805023401.sh: line 37: go: not found

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events