Search code examples
ivy

How to use wildcards in IVY: <artifacts pattern="..."/>


I want to publish my artifacts with ivy but my build path is dynamic and not static since it contains the version TAG i.e.: "build_02.14Test3".

This is from my build.xml:

<target name="go" depends="install-ivy" 
            description="--> create and publish">
            <property environment="env"/>   
            <fail unless="env.PUBREVISION" message="no publish revision set!"/>
        <ivy:resolve/>  
        <ivy:publish resolver="components" pubrevision="${env.PUBREVISION}">
            <artifacts pattern="../Java/build_*/Release/[artifact].[ext]"/>
        </ivy:publish>
    </target>

The whole build.xml file:

<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.    
-->
<project name="build-ivy" default="go" xmlns:ivy="antlib:org.apache.ivy.ant">
    <!-- 

        More information can be found at http://ant.apache.org/ivy/
        -->

    <!-- here is the version of ivy we will use. change this property to try a newer 
         version if you want -->
    <property name="ivy.install.version" value="2.4.0" />
    <property name="ivy.jar.dir" value="${basedir}/ivy" />
    <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />

    <property name="build.dir" value="build" />
    <property name="src.dir" value="src" />


    <target name="download-ivy" unless="skip.download">
        <mkdir dir="${ivy.jar.dir}"/>
        <!-- download Ivy from artifactory so that it can be used even without any special installation -->
        <echo message="installing ivy..."/>
        <get src="https://artifactory.company.com/artifactory/virtual-maven/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
             dest="${ivy.jar.file}" usetimestamp="true" username="svcbuild" password="**********************"/>
    </target>

    <!-- ================================= 
          target: install-ivy         
            this target is not necessary if you put ivy.jar in your ant lib directory
            if you already have ivy in your ant lib, you can simply remove this
            target and the dependency the 'go' target has on it
         ================================= -->
    <target name="install-ivy" depends="download-ivy" description="--> install ivy">
        <!-- try to load ivy here from local ivy dir, in case the user has not already dropped
              it into ant's lib dir (note that the latter copy will always take precedence).
              We will not fail as long as local lib dir exists (it may be empty) and
              ivy is in at least one of ant's lib dir or the local lib dir. -->
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
                  uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>    

    <!-- ================================= 
          target: go
                    Go ivy, go!
         ================================= -->
   <target name="go" depends="install-ivy" 
            description="--> create and publish">
            <property environment="env"/>   
            <fail unless="env.PUBREVISION" message="no publish revision set!"/>
        <ivy:resolve/>  
        <ivy:publish resolver="components" pubrevision="${env.PUBREVISION}">
            <artifacts pattern="../Java/build_*/Release/[artifact].[ext]"/>
        </ivy:publish>
    </target>


    <!-- ================================= 
          target: clean              
         ================================= -->
    <target name="clean" description="--> clean the project">
        <delete includeemptydirs="true" quiet="true">
            <fileset dir="${src.dir}" />
            <fileset dir="${build.dir}" />
        </delete>
    </target>

    <!-- ================================= 
          target: clean-ivy              
         ================================= -->
    <target name="clean-ivy" description="--> clean the ivy installation">
        <delete dir="${ivy.jar.dir}"/>
    </target>

    <!-- ================================= 
          target: clean-cache              
         ================================= -->
    <target name="clean-cache" depends="install-ivy" 
            description="--> clean the ivy cache">
        <ivy:cleancache />
    </target>
</project>

Basically all I wanna know is why my wildcard "*" is not working and how to fix it.

When running my pipeline I run into the issue that the wildcards are not recogniced:

[ivy:publish] :: delivering :: COMPANY#some.product;working@BUILD_PC :: 02.14Test11 :: integration :: Fri Feb 09 09:13:36 CET 2018
[ivy:publish]   options = status=integration pubdate=Fri Feb 09 09:13:36 CET 2018 validate=true resolveDynamicRevisions=true merge=true resolveId=null pubBranch=null
[ivy:publish]   delivering ivy file to D:\gr\builds\3d9e5594\0\plast\products\some.product\Java\build_*\Release\ivy.xml

BUILD FAILED
D:\gr\builds\3d9e5594\0\plast\products\some.product\ivy\build.xml:70: COMPANY#some.product;working@BUILD_PC: java.io.FileNotFoundException: D:\gr\builds\3d9e5594\0\plast\products\some.product\Java\build_*\Release\ivy.xml (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
    at org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater.update(XmlModuleDescriptorUpdater.java:135)
    at org.apache.ivy.core.deliver.DeliverEngine.deliver(DeliverEngine.java:207)
    at org.apache.ivy.Ivy.deliver(Ivy.java:607)
    at org.apache.ivy.ant.IvyDeliver.doExecute(IvyDeliver.java:420)
    at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:271)
    at org.apache.ivy.ant.IvyPublish.doExecute(IvyPublish.java:308)
    at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:271)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    at org.apache.tools.ant.Main.runBuild(Main.java:857)
    at org.apache.tools.ant.Main.startAnt(Main.java:236)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)

Ivy.xml as requested (Note I replaced company and product names!) :

<ivy-module version="2.0">
    <info organisation="MyOrganisation" module="Organisation.product" />
    <publications>

<artifact name="Data1" ext="cab" type="binaries" />
<artifact name="Organisation product" ext="msi" type="binaries" />
<artifact name="setup" ext="exe" type="binaries" />
<artifact name="splash" ext="bmp" type="binaries" />
<artifact name="Java/jre-8u131-windows-i586" ext="exe" type="binaries" />
<artifact name="ProdA RemTool/Data1" ext="cab" type="binaries" />
<artifact name="ProdA RemTool/ProdA RemTool 01.36" ext="msi" type="binaries" />
<artifact name="ProdA RemTool/setup" ext="exe" type="binaries" />
<artifact name="ProdA RemTool/splash" ext="png" type="binaries" />
<artifact name="ProdA RemTool/viewsimba.splash" ext="bmp" type="binaries" />

 </publications>

</ivy-module>

Solution

  • The solution to my problem was to fix the build path like this:

    <artifacts pattern="../Java/build_${env.PUBREVISION}/Release/[artifact].[ext]"/>
    

    since ${env.PUBREVISION}/ contains the TAG which is my build folder :)