Downloading nexus artifacts - jenkins

I am using ANT to build artifacts(finally all artifacts will be zipped in one zip file) and jenkins plugin 'Nexus Artifact Uploader' to upload artifact to nexus repository.
I want to download the artifact(zip file) from nexus repository using ANT OR jenkins plugin only. I am not supposed to use maven for this task. Also, unix commands like 'wget' or 'curl' are not allowed in my deployment environment. It fails with permission denied error. So, I want solution using either ANT or jenkins plugin only.
Can anyone please help.

You can use below ant project snippet to download artifacts from nexus
<project name="testdown" default="dependencies" basedir=".">
<target name="dependencies">
<mkdir dir="libraries" />
<get src="http://10.135.155.72:8081/repository/maven-central/log4j/log4j/1.2.9/log4j-1.2.9.jar" dest="liblibraries/log4j-1.2.9.jar" usetimestamp="true" />
</target>
</project>

Related

How to automate the Uploading Artifacts to GCP using AntScripts?

I automated the build, create and deployment process of bar files on my local system. Now I want to store generated Artifacts into Google Cloud Storage(buckets) using AntScripts.
Here my doubt is, Can we write Ant scripts for Uploading Artifacts to goggle storage buckets? if we can, what is the list of dependency JARs we need to add into ANT library installation path?
so, Can anyone give a suggestions on this or any reference links would be fine?
Yes, we can write Ant script for Uploading Artifacts to goggle storage buckets
Below is the sample code snippet
<target name="uploadArtifact">
<echo message=" uploading artifacts />
<exec executable="/var/lib/jenkins/google-cloud-sdk/bin/gsutil">
<arg value="cp"/>
<arg value="source-path"/>
<arg value="destination-path"/>
</exec>
</target>

Automate Build from Visual Studio Online using MSBuild & Jenkins

I want to build the code using MSbuild Script in Jenkins. My code repository is on Visual Studio Online. The below script does not copy anything in the output folder on my local machine. Whereas if I am using the same script on my local machine it works fine. Below is the script I am using for my build:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<BuildArtifactsDir Include="D:\Jenkins\jobs\Test\workspace\BuildArtifacts\"/>
<TeamFoundationServerUrl Include="https://XXX.visualstudio.com/DefaultCollection/XXX-XXX/"/>
<SolutionFile Include="$(TeamFoundationServerUrl)*.sln"/>
</ItemGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)'=='' ">Release</Configuration>
<BuildPlatForm Condition="'$(BuildPlatForm)'=='' ">Any CPU</BuildPlatForm>
</PropertyGroup>
<Target Name="Compile" DependsOnTargets="Init">
<MSBuild Projects="#(SolutionFile)" Targets="Rebuild"
Properties="OutDir=%(BuildArtifactsDir.FullPath);Configuration=$(Configuration);Platform=$(BuildPlatform)"/>
</Target>
<Target Name="Init">
<MakeDir Directories="#(BuildArtifactsDir)"/>
</Target>
My Environment:
Jenkins: On my local host.
MSBuild Plugin in Jenkins.
Visual Studio Online for Code repository.
You cannot get the solution from VSO/TFS via msbuild directly.
To connect to VSO/TFS server from Jenkins, you can install TFS Plug-in in your Jenkins server via "Manage Jenkins -> Manage Plugins -> Available -> Team Foundation Server Plug-in". And then configure your project like following:
The plug-in will get the latest solution from your VSO/TFS server and copy it to your Jenkins server, you can then update your msbuild script accordingly.
Please note that you need to use "Alternate authentication credentials" to log in VSO/TFS server with this plug-in. To enable this feature, sign in your VSO/TFS account, enable it under "My Profile/Security/Alternate authentication credentials".

In Ivy what does impossible to publish artifacts FileNotFoundException Error Mean?

I'm working within a large build system that uses Ant/Ivy. I try to use a predefined ant task that uses ivy:publish ant task and get this error:
impossible to publish artifacts for com.company.project1.proj1#MySupportJar;working#server1: java.io.FileNotFoundException: /path_to/ivy-repository/com.company.project1.proj1/MySupportJar/5.1.3.part/MySupportJar-5.1.3.jar (No such file or directory)
The directory in the error message exists up to the version number part (5.1.3.part).
I am new to Ivy but think I get the basics of how it works. I can not find much on the exact meaning of this error so if someone could help or point me to an explanation I think I could resolve the issue from there.
Ant target
<target name="publish-shared" depends="ivyInit, resolve"
description="Publish to the shared repository">
<ivy:publish pubrevision="5.1.3"
resolver="shared"
pubdate="${timestamp}"
forcedeliver="true"
update="true"
conf="distro, docs">
<artifacts pattern="dist/[artifact].[ext]"/>
</ivy:publish>
</target>
Ivy file snippet
<publications>
<artifact name="MySupportJar" type="jar" conf="distro" />
<artifact name="MySupportJar-source" type="source" ext="jar" conf="docs" />
</publications>
Thanks.
Thanks for all the suggestions. Turns out to be a simple solution that I was not looking for.
The problem was permissions at /path_to/ivy-repository/com.company.project1. I did not have write permission. The .part file is a temporary file written by Ivy. Ivy could not write the temporary file so when it got to reading the file it failed to find it.
I'm answering this so that it might help someone later.
Thanks.
I'm fairly new to Ant with Ivy too. What I've done is combine a local Maven repository (Artifactory), with Jenkins as a continuous integration server. When we build a jar, I also produce the Maven pom.xml with it. Then, I use the mvn deploy:file command to deploy the desired build to our Maven repository.
The developer manually deploys the jar to our Maven repository via the Promoted Build plugin to Jenkins. The developer selects the build to deploy to Maven, and then pretty much presses a button, and that build will be deployed.
I actually produce two pomswith each build. One ispom.xmland the other ispom-snapshot.xml`. We deploy the snapshot with each build, so other developers can use the latest jar instead of the officially deployed one. I've put the whole thing in github if you're interested.
The only decent Ant/Ivy documentation I've seen is Manning's Ant in Action by Steve Loughram. If it wasn't for that, I probably would have never even tried Ant with Ivy. The online Ant/Ivy documentation at Apache is just plain awful.
I've looked over what you have. I suspect it might be an issue with your ivy-settings.xml file. Somewhere, it's getting the part string as the valid location for publishing the file. Otherwise, I have no idea.
As I said, we use a Maven repository for our site repository, and then use Maven to actually deploy the jars to the repository. I simply found that much easier to do it that way than to figure out how to do this in pure Ivy. Besides, it also means that our Maven projects can also use the jars from our Ant/Ivy projects.

Is the [conf] token respected when publishing files using Ivy?

I'm learning Ivy (http://ant.apache.org/ivy/) and integrating it as part of our build process. It's going pretty well, but I'm stuck on something with the Ivy publish task. Specifically, I'd like to publish to the local repository with the following pattern (which includes the name of the current configuration):
${ivy.local.default.root}/[organisation]/[module]/[revision]/[type]s/[conf]/[artifact].[ext]
So I set up my custom resolver:
<filesystem name="modifiedLocalRepo">
<ivy pattern="${ivy.local.default.root}/[organisation]/[module]/[revision]/[type]s/[conf]/[artifact].[ext]" />
<artifact pattern="${ivy.local.default.root}/[organisation]/[module]/[revision]/[type]s/[conf]/[artifact].[ext]" />
</filesystem>
And configured the publish task:
<ivy:publish
settingsRef="ivy.ext.settings.custom" <!--Location of definition of modifiedLocalRepo-->
resolver="modifiedLocalRepo"
artifactspattern="bin/Debug/[module].[ext]"
pubrevision="1.1-Test"
overwrite="true"
conf="primary"
/>
And have the conf defined in the ivy.xml file:
<info organisation="Mine" module="Dependency"/>
<configurations defaultconf="primary"> <!--Don't think defaultconf should be necessary-->
<conf name="primary"/>
</configurations>
<publications>
<artifact name="Dependency" ext="dll" type="bin" conf="primary"/>
<artifact name="Dependency" ext="pdb" type="bin" conf="primary"/>
</publications>
I have the process working, ivy configured, resolved, the project building, and the artifacts published (using my custom resolver above). But the [conf] token is always resolving to "default." So the published directory has the structure:
\.ivy2\local\Mine\Dependency\1.1-Test\bins\default\
instead of the structure
\.ivy2\local\Mine\Dependency\1.1-Test\bins\primary\
I've been tinkering around with it, setting the conf value, defaultconf value, etc. everywhere they are valid but it's always "default."
I'm using ant to do the build, and have run in debug mode (-d), inspected the output and noticed nothing useful. I've looked through the output of <echoproperties\> and noticed nothing useful. I've read through the Ivy documentation and only found use of [conf] as a token in retrieve and report output.
I can attach the full xml files I'm using to do my limited test build if it would be useful.
Is the [conf] token valid/respected in the artifact pattern for an Ivy publish? If so, what am I missing? Thanks!
Update:
Was using Ivy 2.3.0-rc2 and decided to try to roll back and use Ivy 2.0.0. Same issue.
Take a look at my Ivy project in github. I set it up, so you can easily add it into an existing Ant project.
We use a Maven repository, so I have it setup to create a pom.xml, and then use mvn deploy:deploy-file to deploy it back to the Maven repository. We use Jenkins for our build, so we use Jenkins to run the mvn deploy-file to do the deployment. I guess we could use <ivy:publish>, but never really tried it.

Maven Ant Tasks: Install artifact (artifact:install) with unknown target filename

In my Ant script, i'm using the Maven Ant tasks to install an artifact to the local repository, like this:
<target name="installProject">
<artifact:pom id="mypom" file="${user.dir}/pom.xml" />
<artifact:install file="target/myproject-1.0.jar">
<pom refid="mypom"/>
</artifact:install>
</target>
What i don't like about this approach is that i have to define the name of the Jar I want to install explicitely: target/myproject-1.0.jar But what if the name of that Jar changes? I want to have a more generic approach. How can i let Maven Ant Tasks install all artifacts that Maven would also install when running mvn clean install in the same dir on commandline (where I DON'T have to provide which Jar i want to install)?
(yes, i could also just call Maven with <exec executable="mvn" ...>, but I think it's cleaner to use Maven Ant Tasks for this)
Nobody knows what your build.xml produces so you need to pass desired artifact names to ant. It can be done through project.groupId, project.artifactId, project.version properties that should be available in your antrun element.
Then after you build.xml worked. You can use attachartifact ant task to attach your artifacts to maven. I.E.
<attachartifact file="${project.build.directory}/${project.artifactId}-${project.version}.jar" type="jar"/>
After that when you performing maven install it install your ant artifacts.

Resources