`
sillycat
  • 浏览: 2539921 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

    java/maven/tomcat环境变量配置

    开发项目必备的环境变量配置,其中包含java/maven/tomcat环境变量配置

    安装Jenkins的git和maven插件

    2. 在Jenkins管理界面手动上传插件并安装。 3. 配置Git全局设置和SSH密钥。 4. 配置Maven全局工具。 5. 创建Jenkins作业,设置构建触发器和Maven目标。 通过以上步骤,你可以成功地在Jenkins中集成Git和Maven,实现...

    jenkins 2.346.1 git maven ssh插件

    jenkins 2.346.1,jdk8 适用 git maven ssh插件

    在 CentOS 8 上安装Jenkins的方法

    2、启用Jenkins存储库。运行以下命令下载并导入GPG密钥 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo sudo rpm –import https://jenkins-ci.org/

    Jenkinsfile调用jdk命令和maven或grandle编译命令工具配置

    Jenkinsfile 调用 JDK 命令和 Maven 或 Gradle 编译命令工具配置 Jenkinsfile 调用 JDK 命令和 Maven 或 Gradle 编译命令工具配置 在 Jenkins pipeline 中,我们经常需要使用 JDK 命令和 Maven 或 Gradle 编译命令...

    jenkins的maven工具

    jenkins的maven工具jenkins的maven工具 jenkins的maven工具 jenkins的maven工具 jenkins的maven工具 jenkins的maven工具jenkins的maven工具

    jenkins 离线安装maven插件集合jenkins-maven.zip

    在大多数Linux系统中,该目录为`/var/lib/jenkins/plugins`。确保你有足够的权限执行此操作,如果没有,可能需要以root身份或者使用sudo执行。 3. **重启Jenkins服务**: 完成解压后,需要重启Jenkins服务以加载新...

    jenkins实现maven项目自动部署到tomcat

    ### Jenkins 实现 Maven 项目自动部署到 Tomcat 在当今快速发展的软件开发环境中,持续集成(CI)与持续部署(CD)已经成为不可或缺的部分。本文将详细介绍如何利用 Jenkins 实现 Maven 项目的自动部署到 Tomcat ...

    jenkins+testng+reportng+maven+java环境搭建

    jenkins+testng+reportng+maven+java环境搭建 本文将指导测试人员搭建jenkins+testng+reportng+maven+java环境,涵盖了Eclipse环境准备、Maven配置、TestNG插件安装、ReportNG报告引入等内容。 一、Eclipse 环境...

    Windows平台搭建Jenkins+maven+git实现自动发布已经越过几道坑

    - **Build配置**: 指定Maven命令(如`install`、`package`等)。 - **构建后操作**: 选择`Deploy war/ear to a container`,以部署到Tomcat容器中。 **注意事项**: - **坑1**: 确保Git配置正确,尤其是指向`.exe`...

    实现Jenkins docker部署,设置svn/maven/jdk/ssh,编写自动部署工程脚本

    第一步:docker search jenkins,找到评星最多的官方镜像,pull后创建容器,没想到无法启动,无奈放弃,选用第二个jenkins/jenkins,此为第一个坑:-( 第二步:创建容器: 新建目录 /data/jenkins_home,然后 ...

    Jenkins_Maven_Git 持续集成及自动化部署 GentOS版

    ### Jenkins、Maven与Git在CentOS上的持续集成与自动化部署 #### 一、环境搭建概述 本篇文章主要介绍如何在CentOS系统上通过Jenkins、Maven与Git实现持续集成(CI)与自动化部署的过程。Jenkins作为CI/CD流水线的...

    4.Jenkins持续集成Maven讲解

    【Jenkins持续集成Maven讲解】 在现代软件开发过程中,持续集成(Continuous Integration,简称CI)扮演着至关重要的角色。Jenkins作为一款广泛使用的开源持续集成工具,它可以帮助开发团队快速、频繁地集成代码,...

    jenkins中关于git和maven的插件

    jenkins用于持续集成git中的maven工程,此时需要添加git-plugin插件。在线安装慢,从官网下载很慢。所以提供给大家。

    maven jenkins的jar

    在“maven2 用于hudson插件开发的jar”这个场景中,我们可以推断这是关于使用Maven2版本来构建Jenkins(前身Hudson)插件的实践。开发者可能需要在他们的环境中安装特定的Maven插件,如`maven-hpi-plugin`,这个插件...

    jenkins subversion 插件 2.15.4

    解决jenkins 升级后报:FATAL: org/apache/commons/digester/Digester java.lang.ClassNotFoundException: org.apache.commons.digester.Digester 的问题

    Java项目包 Jenkins+Maven+Gitlab+Tomcat 自动化构建打包、部署

    2. **配置Maven**:在Jenkins的构建环境中,指定Maven的路径并添加任何必要的Maven配置,如pom.xml文件的位置、构建目标等。例如,可以使用`mvn clean install`命令进行构建。 3. **连接Gitlab**:在Gitlab项目中...

    Jmeter+Jenkins+maven接口自动化集成.rar

    【Jmeter+Jenkins+maven接口自动化集成】 接口自动化测试是现代软件开发中不可或缺的一环,它可以有效地提高测试效率,确保系统的稳定性和可靠性。在这个项目中,我们将利用JMeter、Jenkins和Maven三个强大的工具...

Global site tag (gtag.js) - Google Analytics