I'm trying to set up sfdx on Bitbucket Pipelines.
It's going well but I'm facing a weird issue when using the steps feature.
Here's a snippet of my build file:
- step:
name: Auth. with DevHub
script:
- sfdx force:auth:jwt:grant -i $CLIENT_ID -f jwt/server.key -u $DEVHUB_USERNAME --setdefaultdevhubusername --setalias DevHub
- sfdx force:org:list
- step:
name: Create Scratch Org.
script:
- sfdx force:org:list
- sfdx force:org:create -f environments/scratchorg1-scratch-def.json -v DevHub -a bitbucket_build_$BITBUCKET_BUILD_NUMBER
Here's what the first force:org:list outputs:
+ sfdx force:org:list
=== Orgs
ALIAS USERNAME ORG ID CONNECTED STATUS
─── ────── ────────────────────────────────── ────────────────── ────────────────
(D) DevHub davin.casey+sfdx-trial@pexlify.com 00D1r000002cUfcEAE Connected
No active scratch orgs found. Specify --all to see all scratch orgs
and the second:
+ sfdx force:org:list
ERROR: No orgs can be found.
Try this:
Use one of the commands in force:auth or force:org:create to add or create new scratch orgs.
When you read the documentation for Pipelines, that appears to be expected behaviour:
Each step in your pipeline will start a separate Docker container to run the commands configured in the script. Each step can be configured to:
Use a different Docker image. Configure a custom max-time. Use specific caches and services. Produce artifacts that subsequent steps can consume.
So it's spinning up a fresh image for each step, but we can pass artifacts to subsequent steps. Fine.
So I updated my build file to look like:
- step:
name: Auth. with DevHub
script:
- sfdx force:auth:jwt:grant -i $CLIENT_ID -f jwt/server.key -u $DEVHUB_USERNAME --setdefaultdevhubusername --setalias DevHub
- sfdx force:org:list
artifacts:
- .sfdx/**
- config/**
- environments/**
- sfdx-project.json
- jwt/**
- step:
name: Create Scratch Org.
script:
- sfdx force:org:list
- sfdx force:org:create -f environments/scratchorg1-scratch-def.json -v DevHub -a bitbucket_build_$BITBUCKET_BUILD_NUMBER
artifacts:
- .sfdx/**
- config/**
- environments/**
- sfdx-project.json
- jwt/**
Now, I can see the artifacts being prepared & used in each step.
'Auth. with DevHub teardown':
Build teardown
10s
Searching for artifacts matching .sfdx/**
Compressing artifact /opt/atlassian/pipelines/agent/build/.sfdx/orgs/test-oitz1ujqhgka@example.com/metadataTypeInfos.json
Compressing artifact /opt/atlassian/pipelines/agent/build/.sfdx/orgs/test-oitz1ujqhgka@example.com/sourcePathInfos.json.bak
Compressing artifact /opt/atlassian/pipelines/agent/build/.sfdx/orgs/test-oitz1ujqhgka@example.com/sourcePathInfos.json
Compressing artifact /opt/atlassian/pipelines/agent/build/.sfdx/sfdx-config.json
Compressed artifact in 0 seconds
Uploading artifact of 10 KB
Successfully uploaded artifact in 1 seconds
Searching for artifacts matching config/**
Compressing artifact /opt/atlassian/pipelines/agent/build/config/testorg11384827171-scratch-def.json
Compressing artifact /opt/atlassian/pipelines/agent/build/config/scratchorg1-scratch-def.json
Compressing artifact /opt/atlassian/pipelines/agent/build/config/project-scratch-def.json
Compressing artifact /opt/atlassian/pipelines/agent/build/config/sfdx-trial-scratch-def.json
Compressed artifact in 0 seconds
Uploading artifact of 739 bytes
Successfully uploaded artifact in 1 seconds
Searching for artifacts matching environments/**
Compressing artifact /opt/atlassian/pipelines/agent/build/environments/project-scratch-def.json
Compressed artifact in 0 seconds
Uploading artifact of 241 bytes
Successfully uploaded artifact in 1 seconds
Searching for artifacts matching sfdx-project.json
Compressing artifact /opt/atlassian/pipelines/agent/build/sfdx-project.json
Compressed artifact in 0 seconds
Uploading artifact of 278 bytes
Successfully uploaded artifact in 1 seconds
Searching for artifacts matching jwt/**
Compressing artifact /opt/atlassian/pipelines/agent/build/jwt/server.csr
Compressing artifact /opt/atlassian/pipelines/agent/build/jwt/server.crt
Compressing artifact /opt/atlassian/pipelines/agent/build/jwt/server.key
Compressed artifact in 0 seconds
Uploading artifact of 2 KB
Successfully uploaded artifact in 1 seconds
'Create Scratch Org. build setup':
Artifact ".sfdx/**": Downloading
Artifact ".sfdx/**": Downloaded 10 KB in 0 seconds
Artifact ".sfdx/**": Extracting
Artifact ".sfdx/**": Extracted in 0 seconds
Artifact "config/**": Downloading
Artifact "config/**": Downloaded 739 bytes in 0 seconds
Artifact "config/**": Extracting
Artifact "config/**": Extracted in 0 seconds
Artifact "environments/**": Downloading
Artifact "environments/**": Downloaded 239 bytes in 0 seconds
Artifact "environments/**": Extracting
Artifact "environments/**": Extracted in 0 seconds
Artifact "sfdx-project.json": Downloading
Artifact "sfdx-project.json": Downloaded 278 bytes in 0 seconds
Artifact "sfdx-project.json": Extracting
Artifact "sfdx-project.json": Extracted in 0 seconds
Artifact "jwt/**": Downloading
Artifact "jwt/**": Downloaded 2 KB in 0 seconds
Artifact "jwt/**": Extracting
Artifact "jwt/**": Extracted in 0 seconds
Artifact ".sfdx/**": Downloading
Artifact ".sfdx/**": Downloaded 10 KB in 0 seconds
Artifact ".sfdx/**": Extracting
Artifact ".sfdx/**": Extracted in 0 seconds
Artifact "config/**": Downloading
Artifact "config/**": Downloaded 739 bytes in 0 seconds
Artifact "config/**": Extracting
Artifact "config/**": Extracted in 0 seconds
Artifact "environments/**": Downloading
Artifact "environments/**": Downloaded 241 bytes in 1 seconds
Artifact "environments/**": Extracting
Artifact "environments/**": Extracted in 0 seconds
Artifact "sfdx-project.json": Downloading
Artifact "sfdx-project.json": Downloaded 278 bytes in 0 seconds
Artifact "sfdx-project.json": Extracting
Artifact "sfdx-project.json": Extracted in 0 seconds
Artifact "jwt/**": Downloading
Artifact "jwt/**": Downloaded 2 KB in 0 seconds
Artifact "jwt/**": Extracting
Artifact "jwt/**": Extracted in 0 seconds
Artifact ".sfdx/**": Downloading
Artifact ".sfdx/**": Downloaded 10 KB in 0 seconds
Artifact ".sfdx/**": Extracting
Artifact ".sfdx/**": Extracted in 0 seconds
Artifact "config/**": Downloading
Artifact "config/**": Downloaded 739 bytes in 0 seconds
Artifact "config/**": Extracting
Artifact "config/**": Extracted in 0 seconds
Artifact "environments/**": Downloading
Artifact "environments/**": Downloaded 241 bytes in 0 seconds
Artifact "environments/**": Extracting
Artifact "environments/**": Extracted in 0 seconds
Artifact "sfdx-project.json": Downloading
Artifact "sfdx-project.json": Downloaded 278 bytes in 0 seconds
Artifact "sfdx-project.json": Extracting
Artifact "sfdx-project.json": Extracted in 0 seconds
Artifact "jwt/**": Downloading
Artifact "jwt/**": Downloaded 2 KB in 0 seconds
Artifact "jwt/**": Extracting
Artifact "jwt/**": Extracted in 0 seconds
So they appear to be working correctly, however the orgs are STILL not carrying across to subsequent steps.
Does anyone know why this might be? I assume the org. list is being stored in a local file somewhere, but I've added everything I can see as an artifact so I've no idea where else to look. Thanks!