Adding a Git tag with app version

You can use Codemagic to create a Git tag and push it to your repository.

Pushing Git tags from Codemagic to repository requires write access to the repository. Depending on the Git service and authentication method, Codemagic may not have write access to your repository and you may need to grant it separately in your Git service settings. We recommend that you create a dedicated app password / personal access token for Codemagic.

  • For repositories hosted on Bitbucket, create an app password with write permission for repositories.
  • For repositories hosted on GitHub, create a personal access token with repo scope.
  • For repositories hosted on GitLab, create a personal access token with write_repository scope.
  1. Add your app password / personal access token to Codemagic as a secure environment variable.

  2. Add the following pre-publish script. Note that you need to replace the placeholders with your actual environment variable name and Git service details.

     #!/usr/bin/env sh
     set -e # exit on first failed commandset
     set -x # print all executed commands to the log
     if [ "$FCI_BUILD_STEP_STATUS" == "success" ]
       git tag $new_version
       git push "https://your-username:$" --tags


    • BUILD_NUMBER is the read-only environment variable that holds the total count of builds for this project in Codemagic.
    • your-username is your Git service username
    • APP_PASSWORD_ENV_VARIABLE is the name of the environment variable that holds your app password / personal access token.
    • is the name of your Git service, e.g., or
    • your-repo is the name of your repository

    Before creating the tag, the script will check if the build was successful.

Make sure to use the https repository URL for pushing. Using the ssh format is not supported with app passwords or personal access tokens