Jenkins Configuration(2)Build Enviroment with maven/ivy

Jenkins Configuration(2)Build Enviroment with maven/ivy

1. Some Linux Commands
1.1 tee
append the console output to file

-a append the file

eg:

>echo " "  | tee -a $BUILD_HOME/logs/all.log



1.2 cp
cp file and directory

-f --force

-p --preserve keep the information of the file and directory

-r  do the same things to the sub directory

eg:

>cp -pfr directory1 directory2



2. Build the Project with Maven
I should have this kind of confirmation in my pom.xml. 

<distributionManagement>
  <repository>
     <id>central</id>
     <name>libs-snapshot-local</name>
     <url>http://some.server.com/artifactory/libs-snapshot-local</url>
  </repository>
</distributionManagement>

And set the username and password in settings.xml 

<servers>

    <server>

      <id>central</id>

      <username>builder</username>

      <password>password</password>

    </server>

    <server>

      <id>snapshots</id>

      <username>builder</username>

      <password>password</password>

    </server>

  </servers>



When I execute the maven command as follow:

>clean source:jar package deploy:deploy --update-snapshots



The package will deploy to my artifactory.

Uploaded: http://some.server.com/artifactory/libs-snapshot-local/com/sillycat/1.0.1-SNAPSHOT/somclass.jar



3. Build the Project with Ivy
Here are the configuration in build.xml:

<propertyname="ivy.install.version"value="2.2.0"/>
<propertyname="ivy.home"value="${user.home}/.ant"/>
<propertyname="ivy.jar.dir"value="${ivy.home}/lib"/>
<propertyname="ivy.jar.file"value="${ivy.jar.dir}/ivy.jar"/>

<ivy:settingsfile="${store.dir}/ivy.settings.xml"/>
<ivy:resolvefile="${store.dir}/ivy.xml"/>

<taskdefresource="org/apache/ivy/ant/antlib.xml"uri="antlib:org.apache.ivy.ant"classpath="${ivy.jar.file}"/>
<targetname="download-ivy"]]>
<mkdirdir="${ivy.jar.dir}"/>
<getsrc="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"dest="${ivy.jar.file}"usetimestamp="true"/>
</target]]>


<!-- ================================= target: resolve ================================= -->
<targetname="resolve"depends="download-ivy"description="--> retreive dependencies with ivy"]]>
<ivy:retrievepattern="${deploy.dir}/lib/[artifact]-[revision].[ext]"type="jar,bundle"sync="true"/>
</target]]>
 

<!-- ================================= target: clean-cache ================================= -->
<targetname="clean-cache-lib"description="--> clean the ivy cache"]]>
<deletedir="${ivy.home}/cache"/>
</target]]>

<targetname="publish"depends="download-ivy"description="publish package to artifactory"]]>
  <ivy:publishresolver="sillycat-snapshots"forcedeliver="true"overwrite="true"publishivy="false"]]>
    <artifactspattern="${deploy.dir}/[artifact].[ext]"/>
  </ivy:publish]]>
</target]]>

I can run the command to manage the jar package

>ant resolve



I can run the command to push my release package to artifactory

>ant publish



Here are the configuration in ivy.settings.xml:

<ivysettings]]>

  <settingsdefaultResolver="main"/>
<credentialshost="repository.sillycat.com"realm="ArtifactoryRealm"username="builder"passwd="password"/>
<propertyname="sillycat-snapshots"value="http://repository.sillycat.com/artifactory/libs-snapshot-local"/>

  <resolvers]]>

    <chain name="main"returnFirst="true"]]>
    <filesystem name="libraries"]]>
        <artifact pattern="${ivy.conf.dir}/lib/[artifact]-[revision].[type]"/>
    </filesystem]]>
            <ibiblio name="ibiblio" m2compatible="true"/>

            <ibiblio name="java-net-maven1"root="http://download.java.net/maven/1"pattern="${java.net.maven.pattern}"m2compatible="false"/>
            <ibiblio name="java-net-maven2"root="http://download.java.net/maven/2/"m2compatible="true"/>
            <ibiblio name="sillycat-snapshots"m2compatible="true"root="${sillycat-snapshots}"/>
      </chain]]>

  </resolvers]]>

</ivysettings]]>



And my ivy.xml will be like this:

<ivy-module version="2.0"]]>

<info organisation="com.sillycat.stores" module="storename" revision="1.0.0-SNAPSHOT"/>  

<configurations]]>
    <conf name="sillycat-snapshots"/>
    <conf name="compile"/>
  <conf name="runtime" extends="compile"/>
</configurations]]>
  
<publications]]>
  <artifact type="war" ext="war"conf="sillycat-snapshots"/>
</publications]]>
<dependencies]]>
  <dependencyorg="commons-lang"name="commons-lang"rev="2.4"conf="runtime->default"/>
  <dependencyorg="net.sf.dozer"name="dozer"rev="5.2.1"conf="runtime->default"]]>
      <excludeorg="commons-logging"name="commons-logging"/>
      <excludeorg="org.springframework"name="spring"/>
      <excludeorg="commons-beanutils"name="commons-beanutils"/>
  </dependency]]>
  <dependencyorg="org.freemarker"name="freemarker"rev="2.3.15"conf="runtime->default"/>
  <dependencyorg="ognl"name="ognl"rev="2.7.3"conf="runtime->default"]]>
      <excludeorg="jboss"name="javassist"/>
  </dependency]]>
  <dependencyorg="org.hamcrest"name="hamcrest-core"rev="1.1"]]>
      <excludeorg="jmock"name="jmock"/>
      <excludeorg="org.easymock"name="easymock"/>
      <excludeorg="junit"name="junit"/>
  </dependency]]>
</dependencies]]>
</ivy-module]]>



Every thing works fine on my local machine. But on the server I got this error message.

Error Message:
Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.

Action: Check the spelling.

Action: Check that any custom tasks/types have been declared.

Action: Check that any <presetdef>/<macrodef> declarations have taken place.

No types or tasks have been defined in this namespace yet




Solution:
>wget http://archive.apache.org/dist/ant/ivy/2.2.0/apache-ivy-2.2.0-bin.tar.gz

>tar zxvf apache-ivy-2.2.0-bin.tar.gz

>cd apache-ivy-2.2.0

>cp ./ivy-2.2.0.jar /opt/apache-ant-1.8.1/lib/

It is working now.



When you want to resolve the war package from artifactory. Do like this:

<dependency org="com.sillycat.stores" name="storename" rev="1.0.0-SNAPSHOT"conf="runtime->default"]]>
      <artifact name="storename" type="war"/>
</dependency]]>


And change the build.xml statements like this:

<target name="resolve" depends="download-ivy" description="--> retreive dependencies with ivy"]]>
<ivy:retrieve pattern="${basedir}/war/[artifact]-[revision].[ext]" type="war,jar,bundle"sync="true"/>
</target]]>


4. Some Tips in Jenkins
Poll SCM using this pattern * * * * *



Execute the maven command base on this >clean source:jar package deploy:deploy --update-snapshots



Trigger another project base on this configuration:

Post-build Actions---> Build other projects ----> Trigger only if build succeeds



Only get the dependency from this maven command >clean dependency:copy-dependencies



Execute the shell script here:

Build ----> Execute shell --->

Command ----> chmod 755 * .; ./some-shell.sh



references:
http://hi.baidu.com/hongszh/item/ae48d648ea62190be93504ee

http://www.2cto.com/os/201112/113221.html

http://www.ningoo.net/html/2007/shell_scripts_stderr_stdout.html



ivy

https://support.sonatype.com/entries/21612333-how-do-i-configure-my-ivy-build-to-publish-artifacts-to-nexus

http://sillycat.iteye.com/blog/564051

http://sillycat.iteye.com/blog/611299



http://www.draconianoverlord.com/2010/07/18/publishing-to-maven-repos-with-ivy.html

你可能感兴趣的:(configuration)