How can I define reusable scripts and run them in parallel steps

Zsolt Szabó
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!
October 9, 2024

Hi,

Given the following pipeline configuration, the Pipeline Validator claims it is good but the pipeline gives an error: 

 

There is an error in your bitbucket-pipelines.yml at [pipelines > default > 3 > parallel > 0]. The step section is empty or null.

Thanks your answer.

My pipeline:


image
: gradle:8.10.1-jdk21

definitions:

steps:
- step: &deploy-step-template
name: Deploy to Environment
trigger: manual
script:
- apt-get update && apt-get install -y jq
- export MAJOR=$(jq -r '.major' version.json)
- export MINOR=$(jq -r '.minor' version.json)
- export PATCH=$(jq -r '.patch' version.json)
- export DATE=$(date +%Y%m%d)
- export VERSION="$MAJOR.$MINOR.$PATCH-$DATE-$BITBUCKET_BUILD_NUMBER"

- apt-get update && apt-get install -y sed
- sed -i "s|{{environment}}|$ENVIRONMENT_NAMESPACE|g" k8s/deployment.yaml
- sed -i "s|{{version}}|$VERSION|g" k8s/deployment.yaml
- pipe: atlassian/kubectl-run:3.11.0
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'k8s/deployment.yaml'

- sed -i "s|{{environment}}|$ENVIRONMENT_NAMESPACE|g" k8s/service.yaml
- pipe: atlassian/kubectl-run:3.11.0
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'k8s/service.yaml'

services:
postgres:
image: postgres:latest
environment:
POSTGRES_DB: torep_db
POSTGRES_USER: torepservice
POSTGRES_PASSWORD: admin123

pipelines:
default:
- step:
name: Build and Test
caches:
- gradle
services:
- postgres
script:
- gradle build
artifacts:
- build/libs/**/*.jar
after-script:
- pipe: atlassian/checkstyle-report:0.3.0

- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.5.1

- step:
name: Generate and push Docker image
trigger: manual
services:
- docker
caches:
- docker
script:
- apt-get update && apt-get install -y jq
- export MAJOR=$(jq -r '.major' version.json)
- export MINOR=$(jq -r '.minor' version.json)
- export PATCH=$(jq -r '.patch' version.json)
- export DATE=$(date +%Y%m%d)
- export VERSION="$MAJOR.$MINOR.$PATCH-$DATE-$BITBUCKET_BUILD_NUMBER"

- echo $DOCKER_HUB_TOKEN | docker login -u $DOCKER_HUB_USERNAME --password-stdin
- docker build -t bsce/2repservice:$VERSION .
- docker push xxx/xxxservice:$VERSION

- parallel:
- steps:
- step:
<<: *deploy-step-template
name: Deploy to Test1
deployment: Test1

- step:
<<: *deploy-step-template
name: Deploy to Test2
deployment: Test2

- step:
<<: *deploy-step-template
name: Deploy to RC1
deployment: RC1

- step:
<<: *deploy-step-template
name: Deploy to RC2
deployment: RC2

1 answer

1 accepted

0 votes
Answer accepted
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 10, 2024

G'day, @Zsolt Szabó 

Welcome to the community!

The steps key under parallel seems to be misplaced. The steps keyword should be at the same indentation level as - parallel, and the list under steps should contain the individual step entries. The correct structure should be:

    - parallel:
        steps:
          - step:
              <<: *deploy-step-template
              name: Deploy to Test1
              deployment: Test1
          - step:
              <<: *deploy-step-template
              name: Deploy to Test2
              deployment: Test2
          - step:
              <<: *deploy-step-template
              name: Deploy to RC1
              deployment: RC1
          - step:
              <<: *deploy-step-template
              name: Deploy to RC2
              deployment: RC  

 I hope this helps.

Regards,
Syahrul

Zsolt Szabó
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!
November 6, 2024

Thanks

Like Syahrul likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events