Deploy plugin, activate it, and update it in apps

Hello everyone,

I am currently creating a few plugins and would like to automatically update the new versions via automation (gitlab ci/cd).

What have I already implemented?
I can deploy the plugins with
npm run deploy and the arguments --tags “latest” --rolling-tags.

But how can I automatically update the apps via my pipeline?

Hi @david.boenisch,

Here is a small sample shell script that should do what you want:

basicAuthCredentials="<tenantId>/<username>:<password>"
baseUrl="https://<tenant-domain>"
appId=855951
packageContextPath="sample-plugin"
targetVersion="2.0.0"

echo "Attempting to upgrade '$packageContextPath' to version '$targetVersion'"

appObj=$(curl --fail --user "$basicAuthCredentials" $baseUrl/application/applications/$appId | jq)
appConfigObj=$(echo "$appObj" | jq '.config')
appConfigRemotesObj=$(echo "$appConfigObj" | jq '.remotes')

packagesUsedInApplication=$(echo "$appConfigRemotesObj" | jq 'keys' | jq -c '.[]')

adjustmentRequired="0"
for package in $packagesUsedInApplication
do
    cleanedPackage=$(echo "$package" | xargs)

    # Only apply logic for package with the context path we try to upgrade/downgrade
    if [[ $cleanedPackage == $packageContextPath@* ]]
    then
        # Retrieve plugins of package installed via the old version
        pluginsOfPackage=$(echo "$appConfigRemotesObj" | jq --arg a "$cleanedPackage" '.[$a]')

        # Generate new package context path with the new version
        newContextPath="$packageContextPath@$targetVersion"

        # Remove old version
        appConfigRemotesObj=$(echo "$appConfigRemotesObj" | jq --arg a "$cleanedPackage" 'del(.[$a])')

        # Add new version
        appConfigRemotesObj=$(echo "$appConfigRemotesObj" | jq --arg a "$newContextPath" --argjson b "$pluginsOfPackage" '.[$a] = $b')

        adjustmentRequired="1"
    fi
done

if [ $adjustmentRequired == "0" ]
then
    echo "It seems like the selected application does no include any plugins of the $packageContextPath package..."
    exit 1 
fi

updateBody=$(echo "{}" | jq --argjson a "$appConfigObj" '.config = $a' | jq --argjson a "$appConfigRemotesObj" '.config.remotes = $a' )

echo "Sending updating application config to: $updateBody"
curl --fail --user "$basicAuthCredentials" $baseUrl/application/applications/$appId -H "Content-Type: application/json" -X PUT -d "$updateBody"

You could execute this script with every new version.

An alternative to running this with every new version might be to run this script once, but this time specify the targetVersion as latest. That way the application will always pick the latest version of your plugin instead of a specific version of your plugin.

Please note that you should always ensure that your plugin and shell are compatible with eachother.

Regards,
Tristan

1 Like