3

Our jenkins jobs using SFDX are dockerized, and we would like to be able to reuse scratch orgs from one job to another.

As a scratch org is linked to one SFDX CLI installation sfdx force:org:list doesn't return the scratch org created inside the previous container, as SFDX installs are considered different.

To solve this issue, I tried using docker volumes to share sfdx cache between containers, but until now it is unsuccessful.

Summary:

  • Jenkins Build 1: force:org:create MYSCRATCH1
  • Jenkins Build 2: I need to find MYSCRATCH1 and interact with it using force:org:list

Jenkinsfile part:

agent { 
    dockerfile {
         args '-u 0:0 -v dxco4sfvol_pmdcache:/tmp/pmdcache -v dxco4sfvol_cache_sfdx:/root/.cache/sfdx' //Forces Container tu run as User Root , store cache dirs on locale volume
         reuseNode true
    }
}

Dockerfile part:

# Install sfdx-cli , sfdx-essentials plugin, sass , eslint
RUN npm install -g sfdx-cli && \
    echo 'y' | sfdx plugins:install sfdx-essentials && \
    npm install -g sass && \
    npm install -g eslint

How could I manage to have the "same" SFDX install for all docker containers ?

Additional info :

  • I don't have access to the file system of the EC2 / Linux AMI server hosting Jenkins
  • Different jobs can run in parallel (so parallel docker containers using SFDX running at the same time)

1 Answer 1

2

I found the solution: mount a volume for container folder /root/.sfdx

With this volume, SFDX keep in memory the scratch orgs created and used between Docker containers.

Example: -v /tmp/myvol_sfdx:/root/.sfdx

Extended example:

agent { 
    dockerfile {
         args '-u 0:0 -m=4g -v -v /tmp/myvol_cache_sfdx:/root/.cache/sfdx -v /tmp/myvol_sfdx:/root/.sfdx' //Forces Container tu run as User Root , store cache dirs on locale volume
         reuseNode true
    }
}

This should also work with named volumes instead of folder volumes.

Example: -v myvol_sfdx:/root/.sfdx

2
  • 1
    Most CI tools also offer a configuration based way of cacheing certain folders and a way of restoring cached items. In GitLab, there are both "Artifact" and "Cache" config file annotations for this purpose
    – abd3721
    Apr 20, 2021 at 23:42
  • 1
    I now use cache in Gitlab CI, and it's sure quite simple compared to Jenkins :) May 8, 2021 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .