How do i pull in 2 materials into a stage using GoCD? - go-cd

I have 2 types of materials:
A static git repo
Artifacts from an upstream pipeline
Down stream i have an AnalysisBuilders that requires both to function. When the task executes, i only seem to have access to the git repository and not the 'web' artifacts.
xml:
<pipeline name="FishAnalysis">
<materials>
<git url="https://fish:XXXXXXX#redacted.com/fish/analysis.git" />
</materials>
<stage name="CommitHandler" cleanWorkingDir="true">
<jobs>
<job name="builder">
<tasks>
<exec command="yarn" workingdir="web">
<arg>install</arg>
<runif status="passed" />
</exec>
<exec command="npm" workingdir="web">
<arg>run</arg>
<arg>build</arg>
</exec>
</tasks>
<artifacts>
<artifact src="web/dist" dest="web" />
<artifact src="web/package.json" dest="web" />
<artifact src="web/node_modules" dest="web" />
<artifact src="web/nginx.conf" dest="web" />
</artifacts>
</job>
</jobs>
</stage>
</pipeline>
.....
<pipeline name="AnalysisBuilders">
<materials>
<pipeline pipelineName="FishAnalysis" stageName="CommitHandler" materialName="FishAnalysis" />
<git url="https://fish:XXXXX#redacted.com/fish/docker.git" dest="docker" materialName="Docker">
</git>
</materials>
<stage name="Builders">
<jobs>
<job name="shellScripts">
<tasks>
<exec command="ls">
<arg>-R</arg>
<arg>.</arg>
<runif status="passed" />
</exec>
</tasks>
</job>
</jobs>
</stage>
</pipeline>
I would expect the ls -R output to have a 'web' & 'docker' folder. It does not. It only has the contents of the docker repo. How do i make both materials available?

Artifacts are not automatically propagated to downstream pipelines. You need to add a fetch artifact task, as shown here:
<tasks>
<fetchartifact pipeline="FishAnalysis" stage="CommitHandler" job="builder" srcdir="web" dest="web">
<runif status="passed" />
</fetchartifact>
<exec command="ls">
...
</exec>
</tasks>
This is because artifacts can be published in multiple upstream jobs and each upstream job can publish different artifacts. Notice that in your upstream material definition in AnalysisBuilders pipeline, you didn't specify a job.
GoCD will ensure that the version of the artifact is correct. That is, it corresponds to the upstream pipeline instance that caused this pipeline to run. Even if you re-run the pipeline sometime later.

Related

How to list the two most recent folders inside a directory using their timestamp

I have a parent folder and inside that I have a few folders. For an automation, I want to take the latest of the two folders according to timestamp.
I have tried to take the latest folder by using timstampselector.
<timestampselector property="latest.modified">
<path>
<dirset dir="MyDirectoryPath">
<include name="*" />
</dirset>
</path>
</timestampselector>
Inside my parent folder, I have the following folders:
test (Last modified on 07/04/2019 10:30 AM)
check (Last modified on 08/04/2019 05:00 PM)
integrate (Last modified on 08/04/2019 12:30 PM)
slave (Last modified on 09/04/2019 05:00 PM)
Our script should take the latest two modified folders, which is in the above case it should be integrate & slave.
How can I achieve that?
Generally speaking, it's a good idea to stay away from ant-contrib whenever possible. This particular problem can be quickly solved with native Ant's resource collections:
<last count="2" id="latest.two.files">
<sort>
<date />
<fileset dir="MyDirectoryPath" />
</sort>
</last>
Full example target:
<target name="select-latest">
<delete dir="testdir" />
<mkdir dir="testdir" />
<touch file="testdir/test" datetime="07/04/2019 10:30 AM" />
<touch file="testdir/check" datetime="08/04/2019 05:00 PM" />
<touch file="testdir/integrate" datetime="08/04/2019 12:30 PM" />
<touch file="testdir/slave" datetime="09/04/2019 05:00 PM" />
<last count="2" id="latest.two.files">
<sort>
<date />
<fileset dir="testdir" />
</sort>
</last>
<echo message="${toString:latest.two.files}" />
</target>
The task you are using is part of Ant-Contrib rather than core Ant. The documentation says you can use the count attribute to say how many items you want to select. In your case, set it to two:
<timestampselector property="latest.modified" count="2">
<path>
<dirset dir="MyDirectoryPath">
<include name="*" />
</dirset>
</path>
</timestampselector>
This appeared to work fine for me: the property was set to a comma-separated list of two directories.

impossible to publish artifacts for.... java.io.IOException: missing artifact lib#MyService;1.0!MyService.jar

Basically I am exploring IVY, to version my binary artifacts and how to do version control automatically using ivy. I found that publish, pubrevision could help me out.
Hence I am trying to publish my jar through IVY. However I am getting below error and build failed.
impossible to publish artifacts for lib#MyService;working#Localhost java.io.IOException: missing artifact lib#MyService;1.0!MyService.jar
Please find my ivy.xml
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="lib" module="MyService" />
<configurations defaultconfmapping="default->default;sources->sources;test->default">
<conf name="sources" transitive="false" visibility="private" />
<conf name="test" transitive="false" visibility="private" />
<conf name="default" transitive="false" />
</configurations>
<publications>
<artifact name="MyService" type="jar"/>
</publications>
<dependencies defaultconf="default">
<dependency org="lib" name="commons-logging-1.1" rev="1.1" />
<dependency org="lib" name="commons-collections-3.2" rev="3.2" />
<dependency org="lib" name="commons-beanutils" rev="1.7.0" conf="default" />
</dependencies>
</ivy-module>
Publish task : Note: dist will resolve my dependency and compile and jar
build.xml
<target name="publish" depends="dist">
<ivy:publish resolver="local" pubrevision="1.0" module="MyService" status="release" forcedeliver="true" update="true">
<artifacts pattern="publish/[organisation]-[artifact].[ext]"/>
</ivy:publish>
</target>
MyService.jar is being created in my build folder.
Can you please assist me, what is wrong with my code. I am pretty new to IVY. So any inputs will be appreciated very much.
Thanks.

Sitecore Feature ActiveDirectory - adding AD domain to the domainManager doesn't work

I'm using Habitat Sitecore. It comes with a bunch of foundation and feature projects. One of the feature projects is Sitecore.Feature.ActiveDirectory.
I'm trying to configure domains from patch files. It is outlined by Kam in this blog.
In the /App_config/Include/Feature/Feature.ActiveDirectory.config, I added the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<switchingProviders>
<membership>
<provider providerName="ad" storeFullNames="false" wildcard="*" domains="ad" />
</membership>
<roleManager>
<provider providerName="ad" storeFullNames="false" wildcard="*" domains="ad" />
</roleManager>
</switchingProviders>
<domainManager>
<domains>
<domain id="ad" type="Sitecore.Security.Domains.Domain, Sitecore.Kernel" patch:after="domain[#id='default']">
<param desc="name">$(id)</param>
<ensureAnonymousUser>false</ensureAnonymousUser>
<locallyManaged>false</locallyManaged>
<isDefault>false</isDefault>
</domain>
</domains>
</domainManager>
</sitecore>
</configuration>
However, I get the following Exception:
A domain specified in the Sitecore.Security.SwitchingRoleProvider provider/domain map could not be found. Domain name: ad
in
<add name="switcher" type="Sitecore.Security.SwitchingRoleProvider, Sitecore.Kernel" applicationName="sitecore" mappings="switchingProviders/roleManager" />
What am I doing wrong?
Domains must be added directly to to Domains.config, located in App_Config\Security. It is not able to be patched. Make it part of your build train.

How to configure a fte ant script so it can perform few task before file transfer

can any one please suggest me some good sites so i can learn how to use FTE & FTE ant script. Basically i want to wite ant script to perform few task before file tranfer.
I resolved it .. below is the solution for reference:
<request version="1.00" xsi:noNamespaceSchemaLocation="FileTransfer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<managedCall>
<originator>
<hostName>X.com</hostName>
<userID>X</userID>
<mqmdUserID>X</mqmdUserID>
</originator>
<agent QMgr="X" agent="X"/>
<reply QMGR="X">reply</reply>
<transferSet priority="1">
<metaDataSet>
<metaData key="com.ibm.wmqfte.SourceAgent">X</metaData>
<metaData key="com.ibm.wmqfte.DestinationAgent">X</metaData>
</metaDataSet>
<call>
<command name="X.xml" type="antscript" retryCount="2" retryWait="30" successRC="0">
<target>X</target>
<property name="trigger.filename" value="${FileName}"/>
</command>
</call>
</transferSet>
<job>
<name>X</name>
</job>
</managedCall>
</request>
WMQ InfoCenter has good information on FTE Ant scripting. You can also look at this developerWorks article.

nant script doesn't display unit test details

Can someone please tell me why my build script (nant) doesn't display the unit test details in the command prompt window? I have verbose set to true, but it doesn't want to display any details about my unit tests. Here's the target:
<target name="run-unit-tests" depends="compile, move.assemblies.for.tests, rebuildDatabase">
<mkdir dir="${tests.output.dir}" />
<nunit2 haltonfailure="true" failonerror="true" verbose="true">
<formatter type="Xml" extension=".xml" outputdir="${tests.output.dir}" usefile="true" />
<test assemblyname="${test.assembly.file}" />
</nunit2>
<echo message="Unit Testing Done!" />
</target>
The command prompt window just displays this:
[mkdir] Creating directory 'C:\Projects\TestProject\build\artifacts\UnitTestOutput'.
[echo] Unit Testing Done!
build:
BUILD SUCCEEDED
Am I missing something here?
Thanks!
I found the answer. I looked at the source for CodeCampServer and saw a line
<formatter type="Plain" />
and added it to my build script so it looks like this:
<nunit2 haltonfailure="true" failonerror="true" verbose="true">
<formatter type="Xml" extension=".xml" outputdir="${tests.output.dir}" usefile="true" />
<formatter type="Plain" />
<test assemblyname="${test.assembly.file}" />
</nunit2>
and now it displays the details.
Sorry to ask the question prematurely on here, but at least it might help someone in the future if they have a similar problem.
Is there a log file in ${tests.output.dir} ? If so, what if you set usefile to false and type to "Plain"?