将变量从VSTS构建传递到build.xml

时间:2018-08-28 18:02:42

标签: ant azure-devops azure-pipelines

我正在VSTS(Visual Studio Team Services)中建立构建管道,并且无法将变量传递给构建。我不知道我应该在构建中实际使用什么语法来获取变量。我在VSTS中创建了变量:VSTS variables 我使用标准的build.xml文件:

<project name="Sample usage of Salesforce Ant tasks" default="deployCodeAndRunTests" basedir="." xmlns:sf="antlib:com.salesforce">

<property file="build.properties"/>
<property environment="env"/>

<!-- Setting default value for username, password and session id properties to empty string 
     so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
     will be treated literally.
-->
<condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
<condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
<condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
    <classpath>
        <pathelement location="ant-salesforce.jar" />           
    </classpath>
</taskdef>          

<!-- Deploy code and run tests.  If test fails, rollback deploy. -->
<target name="deployCodeAndRunTests">
  <sf:deploy
        username="${sf.username}"
        password="${sf.password}"
        sessionId="${sf.sessionId}"
        serverurl="${sf.serverurl}"
        maxPoll="${sf.maxPoll}"
        deployRoot="..\src"
        testLevel="NoTestRun"
        rollbackOnError="true"
        logType="Detail"/>
</target>

关于如何将变量获取到构建的任何建议?

1 个答案:

答案 0 :(得分:0)

要使用来自VSTS的参数运行ant构建,您需要在build.xml中使用property任务来设置它们

<property name="sf.username" value="${sfUsername}"/>
<property name="sf.password" value="${sfPassword}"/>
<property name="sf.serverurl" value="${sfServerurl}"/>    
<property name="sf.testLevel" value="${sfTestLevel}"/>

然后,在VSTS中设置构建时,将其设置为与参数一起运行,并在其中分配VSTS中定义的变量。要使用参数运行ant构建,请使用OptionsVST Ant build job