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

is it possible to run a script before running a pipe?

yivi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 27, 2019

I'm trying to build a pipeline to build and deploy to S3 one of our angular projects.

I can use the atlassian pipe for this (atlassian/aws-s3-deploy:0.2.4), but since I'm using the same build task for staging and production a specific configuration variable needs to be "injected" on artifact to be uploaded with different values to each environment.

The developer asked a file with the URL for the API backend to be inserted (to use the staging or prod API on build).

I thought of running another script step to generate the file (using a value from a deployment variable) on the distribution directory, but this doesn't seem to work:

 

image: node:10.15.1

definitions:
build:
- step: &build-generate
script:
- npm install
- npm run build:prod
artifacts:
- dist/**
deploy: &deploy-to-s3
- step:
name: Deploying
deployment: staging
script:
- echo "var BASE_URL = \"$API_CORE_URL\";" > dist/site-admin/assets/config.js
- pipe: atlassian/aws-s3-deploy:0.2.4
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: "eu-west-1"
S3_BUCKET: $OUR_AWS_BUCKET_NAME
LOCAL_PATH: "dist/site-admin"
ACL: "public-read"
CACHE_CONTROL: 'max-age=3600'
DELETE_FLAG: 'true'
EXTRA_ARGS: '--follow-symlinks'

pipelines:
tags:
release-*:
- step: *build-generate
- step:
<<: *deploy-to-s3
deployment: 'production'
custom:
deploy-to-staging:
- step: *build-generate
- step:
<<: *deploy-to-s3

I get an error saying

No commands or pipes defined for the step at [pipelines > custom > deploy-to-staging > 1 > step]. Check that you have defined a valid "script" section.

 

Apparently this is not valid. How should I do this instead?

1 answer

0 votes
davina
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 27, 2019

Hi @yivi 

You need to move the anchor onto the step i.e.:

  deploy:
- step: &deploy-to-s3

Hope this helps!

yivi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 27, 2019

Thanks @davina Davina. Now I get

There is an error in your bitbucket-pipelines.yml at [pipelines > custom > deploy-to-staging > 1 > step]. To be precise: This section should be a map (it is currently defined as a list).

 

The validator says it's fine, although it's not. Would be nice if the validator ran some of the same checks than the actual thing does.

davina
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 28, 2019

I don't get any validation errors after that fix. 

image: node:10.15.1

definitions:
build:
- step: &build-generate
script:
- npm install
- npm run build:prod
artifacts:
- dist/**
deploy:
- step: &deploy-to-s3
name: Deploying
deployment: staging
script:
- echo "var BASE_URL = \"$API_CORE_URL\";" > dist/site-admin/assets/config.js
- pipe: atlassian/aws-s3-deploy:0.2.4
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: "eu-west-1"
S3_BUCKET: $OUR_AWS_BUCKET_NAME
LOCAL_PATH: "dist/site-admin"
ACL: "public-read"
CACHE_CONTROL: 'max-age=3600'
DELETE_FLAG: 'true'
EXTRA_ARGS: '--follow-symlinks'

pipelines:
tags:
release-*:
- step: *build-generate
- step:
<<: *deploy-to-s3
deployment: 'production'
custom:
deploy-to-staging:
- step: *build-generate
- step:
<<: *deploy-to-s3

 

Try copy the whole file with the fix. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events