How to show git hash number


#1

We have developers here that when they commit to git the trigger will run Bitrise. Bitrise will build it and push it to the app connect store for Testflight internal testing.

I was using Set Xcode Project Build Number which works create to offset the build number and keep increasing.
The problem i am having is the testers are not sure what commit they are testing. What i was trying to do was add the git hash number somewhere. I was thinking to put it in the build code number but the hash is to long. Is there a way to shorten this when sending it.

Does anyone else have any other ideas how distinguish different builds? I know i can add it in the test notes in testflight but it would have to be added manually as far as i know.

Any suggestions would be great.


#2

Hy there!
Could you try geting the shortened comit hash, like git log --pretty=format:'%h' -n 1


https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection


#3

Right I understand how to get the short hash, but how can I automatically put it as the build number.
I was using Set Xcode Project Build Number to offset the build number by 1. Is there a specific way to add the short hash command in the Set Xcode Project Build Number?


#4

in the script you get the short hash, you can add an env var with envman add

like

newHashNumber = git log --pretty=format:'%h' -n 1
envman add newHashNumber

and in that step you simply add in $newHashNumber


#5

So I am able to get the script to work properly. I tried using the variable but it does not seem to work. Please see biterise.yml below.

++ git log --pretty=format:%h -n 1

  • newHashNumber=773d5792

  • envman add newHashNumber

This is my yml file.

  • script:
    title: Do anything with Script step
    inputs:
    - content: |+
    #!/usr/bin/env bash
    # fail if any commands fails
    set -e
    # debug log
    set -x

         # write your script here
         echo "Hello World!"
         newHashNumber=$(git log --pretty=format:'%h' -n 1)
         envman add --key newHashNumber
    
         # or run a script from your repository, like:
         # bash ./path/to/script.sh
         # not just bash, e.g.:
         # ruby ./path/to/script.rb
    
    • cocoapods-install: {}
    • set-xcode-build-number@1.0.7:
      inputs:
      • build_short_version_string: “$XPI_VERSION”
      • plist_path: “$BITRISE_SOURCE_DIR/KDS_IOS/Plist/Info-Dev.plist”
      • build_version_offset: “$newHashNumber”

Not sure if i can add that variable in the build_version_offset. Does that work or can that be done?


#6

Hy there! sorry, I messed up the syntax, it goes like
envman add --key newHashNumer --value '12345'


or there is a step called “Set environment variable”


#7

I changed the syntax in the script. But when i put in the variable it just takes the value.
So for instance is have this below in the script.

newHashNumber=$(git log --pretty=format:’%h’ -n 1)
envman add --key newHashNumber --value ‘Hash’

If I add $newHashNumber in Xcode Project Build Number i will get “Hash”
What am I doing wrong? AM i missing something. I feel like its an easy fix.


#8

hmm I think it should be like this:
envman add --key newHashNumber --value git log --pretty=format:’%h’ -n 1


#9

Thank you actually figured it out it should be

newHashNumber=$(git log --pretty=format:’%h’ -n 1)
envman add --key newHashNumber --value $newHashNumber


#10

Great, Glad you could figure it out! I will remember these 2 lines for my life. :slight_smile:


#11

Unfortunately what I was trying did not work, but it did what it was suppose to do in bitrise.
The app connect store requires you to have an incremental build number to upload. So witht he string from the hash it does not work.
I created another thread to see if there is a way to add anything from bitrise to the test flight release notes/test notes