使用命令-H
时,可以在命令行上指定主机。
让我们说,你已经设置了一个env.hosts
变量和一个主机列表。但有时,您需要仅在一个或两个主机上应用您的功能,并且您需要使用-H
。
使用此参数时如何继续忽略env.hosts
?我没有找到任何关于它的信息。这是实现这个目标的好方法吗?
答案 0 :(得分:1)
只有在未将env.hosts
指定为命令行参数时才能填充env.hosts = env.hosts or ['host1', 'host2', 'host3']
,如:
-H
这样设置CLI参数--hosts
/ env.hosts
时,<?xml version="1.0" encoding="UTF-8"?>
<project name="AntTest" basedir=".">
<description>
AntTest project build file.
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="ExternalLibraries" location="ExternalLibraries"/>
<property name="JenkinsResults" location="Results/JenkinsResults"/>
<property name="TestSuiteName" location="${src}/AntTest.testsuite"/>
<!--Set the classpath for compiling the source files-->
<path id="AntTest.classpath">
<fileset dir="${ExternalLibraries}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="${build}"/>
<pathelement location="${Results}"/>
</path>
<!--Set the framework properties required for the run-->
<target name="setFrameworkProperties">
<propertyfile file="framework.properties" >
<entry key="browser" operation="=" value="${Browser}" />
<entry key="url" operation="=" value="${Url}" />
<entry key="Environment" operation="=" value="${Environment}" />
</propertyfile>
</target>
<!--Creates the directory for the classes-->
<target name="createBuildFolder" depends="setFrameworkProperties">
<mkdir dir="${build}"/>
</target>
<!--Creates the Jenkins results folder-->
<target name="createResultsFolder" depends="createBuildFolder">
<mkdir dir="${JenkinsResults}"/>
</target>
<!--Deletes the old build jenkins results files-->
<target name="DeleteContentsOldResultsFolder" depends="createResultsFolder">
<delete>
<fileset dir="${JenkinsResults}">
<include name="**/*.*"/>
</fileset>
</delete>
</target>
<!--Compile the source code from the source folder to the build folder-->
<target name="compile" depends="DeleteContentsOldResultsFolder" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" includeantruntime="false">
<classpath refid="AntTest.classpath" />
</javac>
</target>
<target name="runtestsuite" description="runs a junit testsuite" >
<antcall id="compileTargetCall" description="Call to target compile" target="compile"/>
<!-- runs a testsuite -->
<junit printsummary="yes" haltonfailure="no">
<classpath refid="AntTest.classpath" />
<test name="${TestSuiteName}" haltonfailure="no" todir="${JenkinsResults}">
<formatter type="xml"/>
</test>
</junit>
<antcall id="deleteBuildFolderCall" description="Call to delete build folder" target="deleteBuildFolder" />
</target>
<!--Deletes the directory for the classes after the current run-->
<target name="deleteBuildFolder">
<delete dir="${build}"/>
</target>
</project>
已经包含加载fabfile时的值,而您没有覆盖其值。
如documentation中所述,从CLI指定的主机列表是优先顺序中的最新列表,因此可能被其他人覆盖。