Post-publish scripts

How to add post-publish scripts in codemagic.yaml

Codemagic has a number of integrations for publishing but you can also publish elsewhere with custom scripts.

Note: Post-publish scripts will be executed even if a build fails. They will stop from being executed only when a build is canceled or times out. You can specify additional conditions using if statements in scripts themselves.

Below are just a few post-publish script examples to illustrate the most common options:

Publish only if .apk was created

publishing:
  email:
    recipients:
      - name@example.com
  scripts:
    name: Check for apk
    script: | 
      apkPath=$(find build -name "*.apk" | head -1)
      if [[ -z ${apkPath} ]]
      then
        echo "No .apk were found"
      else
        echo "Publishing .apk artifacts"
      fi

Report build status

scripts:
  - name: Report build start
    script: # build started
    
    . . .
  
  - name: Build finished successfully
    script: touch ~/SUCCESS
publishing:
  scripts:
    - name: Report build status
      script: | 
        if [  -f ~/SUCCESS ] ; then
           # build successful
        else
           # build failed
        fi
  
  publishing:
    scripts:
      - name: To get artifact URL
        script: | 
          ARTIFACT_TYPE=".apk" 
          ARTIFACT_URL=$(echo $CM_ARTIFACT_LINKS | jq -r '.[] | select(.name | endswith("'"$ARTIFACT_TYPE"'")) | .url')