Abraham P
Abraham P

Reputation: 15471

Passing pipeline parameters to orb CircleCI

I'm trying to run my E2E tests via an API call at staging deploy using this blog tutorial: https://circleci.com/blog/pipeline-orchestration-circleback/

My E2E pipeline relies on the cypress orb, full code below:

version: 2.1
parameters:
  triggering-pipeline-id:
    type: string
    default: ""
orbs:
  discord: antonioned/[email protected]
  cypress: cypress-io/cypress@3
executor: cypress/default


commands:
  approve-job-in-triggering-pipeline:
    steps:
      - run:
          name: Ping CircleCI API and approve the pending job
          command: |
            echo << pipeline.parameters.triggering-pipeline-id >>
            if ! [ -z "<< pipeline.parameters.triggering-pipeline-id >>" ] 
            then
              workflow_id=$(curl --request GET \
                --url https://circleci.com/api/v2/pipeline/<< pipeline.parameters.triggering-pipeline-id >>/workflow \
                --header "Circle-Token: $CIRCLECI_API_KEY" \
                --header "content-type: application/json" \
              | jq -r '.items[0].id')

              echo $workflow_id
              
              waiting_job_id=$(curl --request GET \
                --url https://circleci.com/api/v2/workflow/$workflow_id/job \
                --header "Circle-Token: $CIRCLECI_API_KEY" \
                --header "content-type: application/json" \
              | jq -r '.items[] | select(.name == "wait-for-triggered-pipeline").id')

              echo $waiting_job_id

              curl --request POST \
                --url https://circleci.com/api/v2/workflow/$workflow_id/approve/$waiting_job_id \
                --header "Circle-Token: $CIRCLECI_API_KEY" \
                --header "content-type: application/json"

            fi
          when: always       

workflows:
 e2e-tests:
    jobs:
    - cypress/run:
        parameters: { "triggering-pipeline-id": << pipeline.parameters.triggering-pipeline-id >> }
        name: "Firefox"
        cypress-command: npm run test:firefox
        install-browsers: true
        cypress-cache-key: custom-cypress-cache-v1-{{ arch }}-{{ checksum "package.json" }}
        cypress-cache-path: ~/.cache/custom-dir/Cypress
        working-directory: /home/circleci/project
        post-steps:
          - approve-job-in-triggering-pipeline
        context:
          - webapp-e2e

However, when I attempt to run this pipeline (through API or otherwise), I get:

Error calling workflow: 'e2e-tests'
Error calling job: 'cypress/run'
Error calling command: 'approve-job-in-triggering-pipeline'
Unknown variable(s): triggering-pipeline-id

Running this without passing the parameters down explicitly results in the same error, which makes sense since as documented here: https://github.com/CircleCI-Public/api-preview-docs/blob/master/docs/pipeline-parameters.md

Pipeline parameters are not available in orbs, including orbs declared locally in your config.yml file

How can I pass my pipeline parameters correctly into the orb?

Thanks!

Upvotes: 2

Views: 326

Answers (1)

Abdirahman Mohamed
Abdirahman Mohamed

Reputation: 1

I am not familiar with the Cypress orb but have you tried using << parameters.triggering-pipeline-id >> instead of << pipeline.parameters.triggering-pipeline-id >> when referencing the paramter?

Upvotes: 0

Related Questions