3

One great feature of Managed Second-Generation Packages (M2GP) is dynamic and flexible versioning. In First-Generation packages we had a strict linear version where each uploaded version dependent on the previous one.

M2GP allows defining nearly arbitrary versioning branches using an ancestor property in the sfdx-project.json.

The issue is that I have to manually define that property before every version create. if I accidentally forget it my new package will break the linear version flow.

Is there a way to set this to standard behavior that such "accidents" don't happen?

1
  • 2
    CLI does not do this automatically so I had to create a gitlab pipeline for version creation to automate version number and ancestor property. I will try to simplify and clear my pipeline and share it with you as soon as possible.
    – Mert YALTI
    Commented May 8, 2020 at 9:46

1 Answer 1

1

What I use is more or less is something like this. This example doesn't have the ancestor info but you can store latest version Id in an ENV variable or a txt file as I do for the version number and before you execute sfdx force:package:version:create you can change it in your project json via simple script.

   before_script:
      # Setup SFDX environment variables
      # https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_env_variables.htm
      - export SALESFORCE_CLI_URL=https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
      - export SFDX_AUTOUPDATE_DISABLE=false
      - export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true
      - export SFDX_DOMAIN_RETRY=600
      - export SFDX_LOG_LEVEL=DEBUG
      # Install Salesforce CLI
      - mkdir sfdx
      - wget -qO- $SALESFORCE_CLI_URL | tar xJ -C sfdx --strip-components 1
      - './sfdx/install'
      - export PATH=./sfdx/$(pwd):$PATH
      # Output CLI version and plug-in information
      - sfdx update
      - sfdx --version
      - sfdx plugins --core

stages:
- release-major-version
- release-minor-version
- release-patch-version

release-minor-version:
    stage: release-minor-version
    only:
    - master
    when: manual
    script:
    # ENV VAR PACKAGE NAME
    - echo $PACKAGE_NAME
    # Increment package version number
    - PACKAGE_VERSION_JSON="$(eval sfdx force:package:version:list --concise --released --packages $PACKAGE_NAME --json | jq '.result | sort_by(-.MajorVersion, -.MinorVersion, -.PatchVersion, -.BuildNumber) | .[0] // ""')"
    - echo $PACKAGE_VERSION_JSON
    - IS_RELEASED=$(jq -r '.IsReleased?' <<< $PACKAGE_VERSION_JSON)
    - MAJOR_VERSION=$(jq -r '.MajorVersion?' <<< $PACKAGE_VERSION_JSON)
    - MINOR_VERSION="NEXT"
    - PATCH_VERSION=$(jq -r '.PatchVersion?' <<< $PACKAGE_VERSION_JSON)
    - BUILD_VERSION="0"
    - 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;
    - VERSION_NUMBER="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION.$BUILD_VERSION"
    - echo $VERSION_NUMBER
    # Create packaged version
    - export PACKAGE_VERSION_ID="$(eval sfdx force:package:version:create --package $PACKAGE_NAME --versionnumber $VERSION_NUMBER --installationkeybypass --wait 10 --json | jq -r '.result.SubscriberPackageVersionId')"
    # Save your PACKAGE_VERSION_ID to a file for later use during deploy so you know what version to deploy
    - echo "$PACKAGE_VERSION_ID" > PACKAGE_VERSION_ID.TXT
    - echo $PACKAGE_VERSION_ID
1
  • I was looking for a solution without custom build scripts. Maybe even a flag by Salesforce. Commented May 8, 2020 at 15:38

You must log in to answer this question.

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