How to resolve error 'Incorrect Type. Expected "build execution unit"' in bitbucket-pipelines.yml
Asked by Deepesh Belani:

Hi All, I am now to Bitbucket pipeline. I am trying to use the YAML anchors to create build steps for dev and qa environments. I am running into an issue 'Incorrect Type. Expected "build execution unit"'. Looking for any help on how to resolve this.

Branches in Repo: dev(MAIN, DEVELOPMENT, PRODUCTION), test

# Template to deploy builds  
image: google/cloud-sdk:latest

definitions:  
caches:  
# Cache zip cli  
zip: /usr/bin  
steps:  
- step: \&zipfile  
name: zip files  
caches:  
- zip  
max-time: 2  
script:  
- apt-get update \&\& apt-get install -y zip  
- zip -r function-source.zip . -x \*.git\* \*.yml \*.md  
- ls -l  
- gcloud config set project my-first-project  
- echo $GCLOUD_API_KEYFILE_NPROD \> gcloud-api-key.json  
- gcloud auth activate-service-account --key-file=gcloud-api-key.json  
- gcloud storage cp function-source.zip gs://my-first-bucket/bitbucket-pipeline  
- step:  
name: deploy to CF  
max-time: 10  
script:  
- gcloud config set project my-first-project  
- echo $GCLOUD_API_KEYFILE_NPROD \> gcloud-api-key.json  
- gcloud auth activate-service-account --key-file=gcloud-api-key.json  
- gcloud functions deploy Hello_World  
--gen2  
--region=us-east4  
--runtime=python311  
--source=gs://my-first-bucket/bitbucket-pipeline/function-source.zip  
--entry-point=hello_http  
--run-service-account=myfirstsa@my-first-project.iam.gserviceaccount.com  
--trigger-http  
--no-allow-unauthenticated

pipelines:  
branches:  
dev:  
- step: \*zipfile


Answers:
author: Theodora Boudale
body: Hi Deepesh and welcome to the community!

I tried using a yml file similar to yours, but I cannot reproduce this error. I see that the second step in your definitions (with the name 'deploy to CF') is missing an anchor, but this shouldn't be an issue if you are not using it anywhere. If you want to use it, you will need to specify an anchor, as you did for the first step.

* Is this the whole yml file you are using or is there additional content you haven't posted here?  

* Where exactly do you see the error you mentioned?  

* Can you please ensure you are using indentation as below (with spaces for indentation, not tabs) and try running another build?

```
# Template to deploy builds
image: google/cloud-sdk:latest

definitions:
  caches:
  # Cache zip cli
    zip: /usr/bin
  steps:
    - step: &zipfile
        name: zip files
        caches:
          - zip
        max-time: 2
        script:
          - apt-get update && apt-get install -y zip
          - zip -r function-source.zip . -x *.git* *.yml *.md
          - ls -l
          - gcloud config set project my-first-project
          - echo $GCLOUD_API_KEYFILE_NPROD > gcloud-api-key.json
          - gcloud auth activate-service-account --key-file=gcloud-api-key.json
          - gcloud storage cp function-source.zip gs://my-first-bucket/bitbucket-pipeline
    - step:
        name: deploy to CF
        max-time: 10
        script:
          - gcloud config set project my-first-project
          - echo $GCLOUD_API_KEYFILE_NPROD > gcloud-api-key.json
          - gcloud auth activate-service-account --key-file=gcloud-api-key.json
          - gcloud functions deploy Hello_World --gen2 --region=us-east4 --runtime=python311 --source=gs://my-first-bucket/bitbucket-pipeline/function-source.zip --entry-point=hello_http --run-service-account=myfirstsa@my-first-project.iam.gserviceaccount.com --trigger-http --no-allow-unauthenticated

pipelines:
  branches:
    dev:
      - step: *zipfile
```

Kind regards,  
Theodora

comments: author: Deepesh Belani
body: Hello Theodora,

Thanks for your reply. The code above is the whole yml file. I am sorry I did not mention the line giving error. It is at below line in the VS code editor. I checked the indentation(VS code) it is using space and not tabs. I think we can ignore this as this is the editor reported issue and not by the pipeline. I have put the new error below.

```
- step: &zipfile
```

Per your suggestion I have used online in editor to format it again and used the BB Validator to confirm the file is valid. After running the pipeline it is giving the error as below though there is a step defined.

-------------------------  

#### Configuration error {#toc-hId-286862700}

There is an error in your bitbucket-pipelines.yml at \[pipelines \> branches \> dev \> 0\]. Step is empty, null, or missing.

-------------------------


author: Theodora Boudale
body: Hi Deepesh,

Thank you for the update.

The new error you see is most likely related to indentation. Unfortunately, the validator doesn't report errors when yaml anchors are used (this is a bug: <https://jira.atlassian.com/browse/BCLOUD-18299>).

If you edit the file online on Bitbucket website, do you see an orange circle next to a line number that indicates where the issue is?

If you cannot figure it out, could you please post a screenshot of the file from the website? If you copy-paste the content here, the indentation will be lost. With a screenshot, I can see if there are any issues with indentation.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud