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

Updating $PATH while running a bitbucket pipeline

Misha _HS_ March 11, 2022

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
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 14, 2022

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

Misha _HS_ March 14, 2022

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
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
March 14, 2022

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
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 15, 2022

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
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
March 11, 2022

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

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

Misha _HS_ March 11, 2022

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
AUG Leaders

Atlassian Community Events