I am running one batch script while running the VSTS build definition. In that batch script I have maven path which is taken from the hosted agent capabilities section. I don't want that path to be hard coded in that batch file. I want to call instead that path using an environmental variable in the script while running the build definition. The path I have taken from hosted agent capabilities section. Below is the batch script.
Using batch script task in VSTS I am calling the below abc.bat file in VSTS build definition.
Batch script:
abc.bat:
call C:\java\maven\apache-maven-3.2.2\bin\mvn.bat install:install-file -Dfile=DevOps/proj_Dep_libs/application-agent-1.0.3.jar -DgroupId=application-agent -DpomFile=DevOps/Pss_Dep_libs/application-agent-1.0.3.pom -DartifactId=application-agent -Dversion=1.0.3 -Dpackaging=jar
Please help me on how to pass the path as a variable in the batch script while running the VSTS build definition.
You can retrieve maven path from the hosted agent capabilities section, then create the variable using the Logging Commands. Then you can use the variable in batch script instead calling maven path.
Create a PowerShell script to set the avariables (Reference below sample, you can also Use the OAuth token to access the REST API), then check in the script into VSTS.
Add a PowerShell task in your definition to run the PS script
3.Use the variable in steps which behind the set variable step
UPDATE:
Well, you can use PAT without the username with below script (If you don't want to hardcode the token in the script, then you can create a secret variable and set the token as the value of the variable, then use the variable in script):