Gradle build using VSTS/TFS

In this post i will show you how we can have gradle projects built on VSTS/TFS.

Pre- requisites:

  1. Java Environment
  2. Android SDK
  3. Sample Android Project (I have considered Android Studio)
  4. Installed Build agent up and running

Please find the below link to download Android SDK

Note: Since I am using Visual Studio Team Services to build, I would be installing the agent on my Local Machine. Because, the “Hosted agent” would not recognize the machine you are working with.

Once the Java Environment is ready, please make sure you have the Android SDK setup ready too.

Please follow the below steps for setting up Android SDK

  1. Copy the SDK to any of the drives (C, D, E etc…)
  1. Add the environment variables as follows

Variable name: ANDROID_HOME

Variable value: Specify the path till sdk. In my case this is how it looks like “D:\adt-                                              bundle-windows-x86_64-20140702\sdk”


3.Update the same in the System Variables-Path too as shown below

 Variable name: Path

Variable value: %ANDROID_HOME%\tools; %ANDROID_HOME%\platform-tools;


4. Open the “services.msc” and verify whether your VSO agent (android) is running or not.

Select the agent that you configured and right click, choose properties.

Go to Logon tab and run as either Local account or Service account as shown below-


The reason is because, the permissions of Network service account should be provided.

Configuring the Build definition

  • Make sure the configured agent is up and running


Note: You must cross check the capabilities of your agents once configured. See to it that the Android SDK shows up with the API levels that you have installed already in your Android SDK as shown below-

In my case I have 4 API levels installed.


  1. Select the “Gradle task” from the list of templates as shown below-


In the options you can pass the arguments as per your needs.

As you can see, this task has many options to perform like code analysis, sonar qube, running unit tests etc. You can setup as per the needs. Since i am performing a neat gradle build, i am not considering it!


2. Map the Location of Gradle wrapper. “.gradle.bat” is the file to be mapped



4.If you want to run a Parallel build, change the options or else retain as it is.



     5.Choose your Repository type


6. Choose the trigger that you want for this build definition



7. Select the agent queue that you want to run this build against.Since we have configured one, we will be using default agent.

5 8. Select copy files task from the utility-


9. Since we are copying the .apk files, pass the below arguments as shown-


$(build.sourcesdirectory) = The local path on the agent where your source code files are downloaded. For example:c:\agent\_work\1\s

$(build.artifactstagingdirectory) = The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent\_work\1\a


10. Add the ” Publish build artifacts” task from the utility-


11. Copy the output to the server/file shared path.


12. Post the build, checkout the detailed summary



13. Navigate to the artifacts tab from the build summary page to verify whether the apk’s are generated and voila



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: