0

I am in the process of creating a CI script that uses GitHub actions for the creation and promotion of new package versions.

For this I have created a shell script that is run after test classes have run and been uploaded to codecov. In there, I reference the node_modules I installed to run sfdx scripts and set environment variables for package numbers and version Ids.

To truncate to the most important part, this is where my script fails:

# Create a new package version (with the previously incremented package version) and import the package version id for further use.
echo "Creating new package version"
node_modules/sfdx-cli/bin/run force:package:version:create -p $PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 30 > result.json

cat result.json
cat result.json | jq '.result.SubscriberPackageVersionId' > packgeversionid.txt

PACKAGEVERSIONID=$( cat packgeversionid.txt )
if [[ "$PACKAGEVERSIONID" == "null" ]]; then    
    echo "Package could not be created"
    exit 1
fi

echo "New Package Version Id: $PACKAGEVERSIONID"

sleep 5
cat sfdx-project.json

#This promotes the package version
echo "Promoting Package Version"
node_modules/sfdx-cli/bin/run force:package:version:promote -p $PACKAGEVERSIONID --noprompt -v devhub

I am able to create a package version just fine. I am cating the result just to ensure that everything works the way I expect it to, and the same goes for the sfdx-project.json

When I get to the force:package:version:promote part, I am running into this error however:

ERROR running force:package:version:promote:  The Subscriber Package Version Id or Package Version Id: "04t<>" isn't defined in the sfdx-project.json. Add it to the packageDirectories section and add the alias to packageAliases with its 04t or 05i ID.

And that although I verified just beforehand that the exact same 04t Id is present in the local sfdx-project.json file.

What steps do I need to take to finish the promotion process?

9
  • I wonder if this might be a race condition somehow? What if you increase sleep from 5 to 60 or so? Does that make it work?
    – sfdcfox
    Jan 8, 2022 at 13:51
  • @sfdcfox can it be a race condition when my cat output clearly shows me the new package version Id, already after 5 seconds of sleep?
    – dschib
    Jan 8, 2022 at 13:59
  • @sfdcfox That's actually the reason I use cat right before my promotion call. And in the Console Output I see in GitHub I see everything I need
    – dschib
    Jan 8, 2022 at 14:05
  • I was more thinking "what if the Id isn't actually available on the server", though I've never seen this, just trying to rule out possibilities.
    – sfdcfox
    Jan 8, 2022 at 16:00
  • Are you sure the sfdx-project.json is well formed and correctly structured?
    – Phil W
    Jan 8, 2022 at 18:55

1 Answer 1

0

The issue was in the retrieval of the Subscriber package version Id.

cat result.json | jq '.result.SubscriberPackageVersionId' > packgeversionid.txt

Retrieves the value behind the Key including the double quotes. What is actually necessary (and something I actually did elsewhere in the script beforehand... duh) is use jq -r to cut away the quotes.

sfdx force:package:version:promote doesn't want you to use double quotes when specifying the package version, so the output that actually included these quotes was not part of the Standard Error message, but part of my input, simply interpreted the wrong way.

You must log in to answer this question.

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