bryan
bryan

Reputation: 9369

Github actions echo command not creating file

I'm in the process of moving a working CircleCI workflow over to Github Actions.

I'm running:

runs-on: ubuntu-latest

container: 
  image: google/cloud-sdk:latest

I run the following command:

echo ${{ secrets.GCLOUD_API_KEYFILE }} > ./gcloud-api-key.json

Before running this command, gcloud-api-key.json has not yet been created. This command works in CircleCI but in Github Actions I get the error:

/__w/_temp/asd987as89d7cf.sh: 2: /__w/_temp/asd987as89d7cf.sh: type:: not found

Does anyone know what this error means?

Upvotes: 9

Views: 3074

Answers (3)

Dunaevsky Maxim
Dunaevsky Maxim

Reputation: 3199

Use quotation marks for echo command:

run: echo "${{ secrets.YOUR_SECRET }}" > secret_file

Upvotes: 0

finisinfinitatis
finisinfinitatis

Reputation: 1599

In order to use secrets which contain more than just one line (like secret jsons) one has to save the base64 encoded secret in Github which makes it one line. On linux the encoding is done via:

cat mysecret.json | base64

Then in the action you need to decode it using

echo ${{ secrets.YOUR_SECRET }} | base64 -d > secret.json

Upvotes: 3

bryan
bryan

Reputation: 9369

The reason was because my secret key was more then 1 line long. Once I made it one line it worked.

Upvotes: 10

Related Questions