This is kind of a follow-up question to this one.
I want to "know" from which branch may Android app was built during the execution of the Gradle build.gradle file and add the branch name to the versionName of my app. 
This is my naive approach:
apply plugin: 'android'
def branch ="test";
android {
    compileSdkVersion 22
    buildToolsVersion '22.0.0'
    // ..
    buildTypes {
        debug {
            minifyEnabled false;
            applicationIdSuffix ".debug"
            versionNameSuffix " branch: " + "$branch"
            debuggable true
            signingConfig signingConfigs.debug
        }
    }
}
task setArgs << {
   branch =  "$word1"
}
task showArgs << {
    println "$branch"
}
When I execute:
gradlew setArgs -Pword1=mybranch showArgs
the branch variable is set and "mybranch" is logged in the console on execution of showArgs.
But when I execute
gradlew setArgs -Pword1=mybranch build
the branch variable is still the default String "test" and therefore useless in the versionNameSuffix.
What's the best way to get this working?