I followed this Trailhead module (Build an Automated CI/CD Pipeline with GitLab) and have successfully created an unlocked package that has a CI/CD pipeline.

There is this part (in the Trailhead module) in the in the .gitlab-ci.yml file that controls the version:

    # Increment package version number
    - echo $PACKAGE_NAME
    - PACKAGE_VERSION_JSON="$(eval sfdx force:package:version:list --concise --released --packages $PACKAGE_NAME --json | jq '.result | sort_by(-.MajorVersion, -.MinorVersion, -.PatchVersion, -.BuildNumber) | .[0] // ""')"
    - IS_RELEASED=$(jq -r '.IsReleased?' <<< $PACKAGE_VERSION_JSON)
    - MAJOR_VERSION=$(jq -r '.MajorVersion?' <<< $PACKAGE_VERSION_JSON)
    - MINOR_VERSION=$(jq -r '.MinorVersion?' <<< $PACKAGE_VERSION_JSON)
    - PATCH_VERSION=$(jq -r '.PatchVersion?' <<< $PACKAGE_VERSION_JSON)
    - if [ -z $MAJOR_VERSION ]; then MAJOR_VERSION=1; fi;
    - if [ -z $MINOR_VERSION ]; then MINOR_VERSION=0; fi;
    - if [ -z $PATCH_VERSION ]; then PATCH_VERSION=0; fi;
    - if [ "$IS_RELEASED" == "true" ]; then MINOR_VERSION=$(($MINOR_VERSION+1)); fi;
    - echo $VERSION_NUMBER

After experimenting on it, I realized only minor version is incremented by 1 each time I install the package to Production.

I would like to know what is the best practice for managing major version, minor version, patch version and build version, given my pipeline very similar to the one described in the Trailhead module (Unit test, Integration test, Package Installment).

1 Answer 1


For production release, you need to have Package promote. sfdx force:package:promote command will help you to do promoting(which will mark it as released package and major version will be upgraded.

Other minor/patches, you need to define the process in your SDLC cycle.

Like for hotpatches you can update patch, if its released as minor version of the package you can update minor version. Build version for every developer build prepared for testing team.

PS: This is not mandatory to use the functions given in Trailhead. You can define your own script to have those numbers populated.

  • How come my major version always stays at zero even if I promote the package? Aug 18, 2020 at 7:35

You must log in to answer this question.

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