I'm attempting to implement what I believe should be pretty basic conditioning but am not having any success. I have a target (deploy.DEVELOPMENT) and within this target I call two macros that backup/restore an ini file we using for configuration. The outline is this:
<target name="deploy.DEVELOPMENT" description="Deploy to DEVELOPMENT">
<echo>START: Deploy to ${mode.dev}</echo>
<echo>SOURCE: ${dir.source}</echo>
<macroBackupSourceConfigFile />
<macroUpdateConfigFile
keyDatasource="${setting.devdsn}"
keyServer="${server.devdevweb11}"
keyAppName="${setting.devappname}"
keyApplicationID="${setting.applicationid}"/>
<macroCopyFiles dirSource="${dir.source}" dirTarget="${dir.devdevweb11}"/>
<macroRestoreSourceConfigFile />
<echo>END: Deploy to ${mode.dev}</echo>
</target>
In certain projects an ini file is not required, therefore I would not need to run either of the two macros, just the macroCopyFiles would run. I'd like to just set a property at the top of my ant file to specify whether these macros should be executed.
Any assistance would be greatly appreciated.
Best Regards,
Gary
I think this is what you need... It will perform a check. If file abc.txt is available, abc.present property will exist. Other target will call check-abc and check wether the property abc.present exists. If so, it will execute, else it will not.
<target name="check-abc">
<available file="abc.txt" property="abc.present"/>
</target>
<target name="do-if-abc" depends="check-abc" if="abc.present">
...
</target>
Related
We upgraded from Jenkins 1.609 to 2.106. When we do a release we want to start a job build number with 1 (Number of builds since the start of the project). We were doing this using a ant script to update the config.xml file, but it does not work in Jenkins 2. The XML file layout has changed some since v 1.0.
While I am think that I no longer want to do a 'replace' (because there is nothing to replace, and I have tried multiple variations of this), I am not sure of the syntax and arguments that I want to use here, to place a value '1' here. I think that I should be using Insert, but with what arguments.
This is the ant code...
<target name="replace.builds.all.time">
<copy file="${BuildConfigPath}" tofile="${BuildConfigPath}.bak" overwrite="true" force="true" />
<xmltask source="${BuildConfigPath}" dest="${BuildConfigPath}">
<replace path="/project/buildWrappers/org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder/versionNumberString/text()" withText="${VersionNumberString}"/>
<replace path="/project/buildWrappers/org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder/oBuildsAllTime/text()" withText="${BuildsAllTime}"/>
</xmltask>
</target>
The second 'replace' line, is where the problem is.
The 1.0 config.xml code looked like this. You can see that oBuildsAllTime had an actual value...
<buildWrappers>
<org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder plugin="versionnumber#1.4.1">
<versionNumberString>${VERSION_NUMBER}</versionNumberString>
<projectStartDate>1969-12-31 05:00:00.0 UTC</projectStartDate>
<environmentVariableName>VERSION_NUMBER</environmentVariableName>
<oBuildsToday>-1</oBuildsToday>
<oBuildsThisMonth>-1</oBuildsThisMonth>
<oBuildsThisYear>-1</oBuildsThisYear>
<oBuildsAllTime>-1</oBuildsAllTime>
<skipFailedBuilds>false</skipFailedBuilds>
<useAsBuildDisplayName>true</useAsBuildDisplayName>
</org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder>
<EnvInjectPasswordWrapper plugin="envinject#1.92.1">
<injectGlobalPasswords>true</injectGlobalPasswords>
<maskPasswordParameters>false</maskPasswordParameters>
<passwordEntries/>
</EnvInjectPasswordWrapper>
</buildWrappers>
The 2.0 config.xml is different in that there is no value for 0BuildsAllTime...
<buildWrappers>
<hudson.plugins.timestamper.TimestamperBuildWrapper plugin="timestamper#1.8.9"/>
<org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder plugin="versionnumber#1.9">
<versionNumberString>10.1.09.${BUILDS_ALL_TIME}</versionNumberString>
<projectStartDate>1969-12-31 05:00:00.0 UTC</projectStartDate>
<environmentVariableName>VERSION_NUMBER</environmentVariableName>
<environmentPrefixVariable/>
<oBuildsToday/>
<oBuildsThisWeek/>
<oBuildsThisMonth/>
<oBuildsThisYear/>
<oBuildsAllTime/>
<worstResultForIncrement>SUCCESS</worstResultForIncrement>
<skipFailedBuilds>false</skipFailedBuilds>
<useAsBuildDisplayName>true</useAsBuildDisplayName>
</org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder>
</buildWrappers>
I want to be able to insert the new build number into the config.xml file, using ant code.
I want to invoke an ant task which should accept multiple test classes for testng and run(not suite xml),
very similar to but comma separated list of test classes. I could not find any clue when I checked the documentation.
Is there a possibility, Please let me know.
This is my ant task to run a single test:
<target name="run-class"
description="run a specific test class. Requires class.name property set to fully-qualified name of class">
<some properties />
<testng classpathref="lib.path"
outputDir="${outputDir}"
workingDir="${workingDir}"
verbose="2"
useDefaultListeners="false"
listeners="${testng.listeners}"
className="${class.name}"
delegateCommandSystemProperties="true"
configFailurePolicy="continue">
<jvm params/>
</testng>
</target>
I would invoke this as : ant run-class -Dclass.name=com.vmware.CreateVM -DParallel=true
I would like to provide another ant task as above which should accept multiple test classes(but not as a suite xml file)
Please refer to TestNG Ant Task documentation and look at the classpath and
classpathref attributes and classfileset element.
I'm try to develop a cruise control step which will process database migration scripts and apply them.
I'd like to be able to get hold of a list of the modifications from the SourceControl (to see if any new database changes need to be applied).
Any ideas how I can achieve this? I know that this information is written into the log xml but I was wondering if there is an easy mechanism to get a reference to this from with an Ant builder.
I have investigated writing a custom CC Listener or Builder plugin but neither supply this in the interface.
We have "svn update" as one of the steps in ant builder, and later we use output redirected to the file (ant property also could be used):
<exec executable="svn" dir=".">
<arg line="up"/>
<redirector output="svnup.log" alwayslog="true" append="true"/>
</exec>
<property name="svnup.log" value="svnup.log"/>
this creates file named "svnup.log" in the build folder with output of "svn up" command.
I think I'm going to try to write a custom plugin implementing Publisher
#Override
public void publish(Element cruisecontrolLog) throws CruiseControlException { XMLLogHelper xmlHelper = new XMLLogHelper(cruisecontrolLog);
Set<Modification> modifications = xmlHelper.getModifications();
for (Modification modification : modifications) {
handleModification(modification);
}
}
Or another idea is to use the timestamp flag in the sscm ant task combined with the cclastbuildtimestamp property supplied to the ant builder to produce a list of files changed since last build.
I have a target, comprised of several steps, that sometimes fails. All this target does is report to Sonar so if it fails, it's not catastrophic. How do I get the build to succeed even if this specific target fails?
I've tried some combinations of 'condition', 'or', 'true', and 'sequential', but Ant hasn't liked any of them.
Following is what I have more or less:
<target name='sonar'>
<!-- do some stuff -->
<sonar:sonar key='key' version='version'/>
</target>
The only way I can see this could work is using the slightly outdated yet still useful antcontrib extension. Then you can use a try/catch directive and just echo your error.
http://ant-contrib.sourceforge.net/tasks/tasks/trycatch.html
I have a tfs 2008 build that I need to add WiX compliation to.
Currently the build executes and compiles and copies all output to a drops location in the following target
<Target Name="AfterCompile"> .... </Target>
I have added another target directly below it that looks like the following
<UsingTask TaskName="HeatDirectory" AssemblyFile="$(WixTasksPath)" />
<Target Name="BuildMsi" DependsOnTargets="AfterCompile">
<Message Text="Start harvesting Website files for Wix compliation" />
<HeatDirectory
ToolPath="$(WixToolPath)"
Directory="$(DropLocation)\Latest\x86\Release\_PublishedWebsites\IFMA.MasterPlan.Web"
GenerateGuidsNow="yes"
ComponentGroupName="Web"
OutputFile="$(MSBuildProjectDirectory)\Setup\Product\Fragments\wwwfiles.wxs"
SuppressFragments="yes"
DirectoryRefId="WebRoot"
KeepEmptyDirectories="yes"
PreprocessorVariable="var.WebRoot"
SuppressRegistry="yes"
SuppressRootDirectory="yes"
SuppressCom="yes"
/>
<Message Text="Finished harvesting Website files for Wix compliation" />
</Target>
The BuildMsi target is never executed but the AfterCompile one definitly is.
The BuildMsi isn't listed in the default build targets
but I thought that since it has a dependency on AfterCompile it would be executed after it.
What am I missing here?
DependsOnTargets lists the targets that must be executed before your target can run, it does not force your target to run after the list of targets run.
See: http://msdn.microsoft.com/en-us/library/t50z2hka(v=VS.90).aspx
If you're using MSBuild 4.0, AfterTargets attribute is what you need:
AfterTargets: Optional attribute.
A semicolon-separated list of target
names. When specified, indicates that
this target should run after the
specified target or targets. This
lets the project author extend an
existing set of targets without
modifying them directly.
Alternatively you can use target injection, which basically is overriding the CompileDependsOn property in your .proj file to include your target at the end. You need to declare this property after the imports of the common target files to ensure it is the last definition of the property.
<PropertyGroup>
<CompileDependsOn>
$(CompileDependsOn);
MyCustomTarget
</CompileDependsOn>
</PropertyGroup>
See "How to extend the visual studio build process" for more details.