我在 jenkins 中有一个设置,可以很好地从开发到生产。
首先是自定义模块存储库的dependencies.yml中的配置
repositories:
- modules:
type: chain
using:
- localModules:
type: local
descriptor: "${application.path}/../[module]/conf/dependencies.yml"
artifact: "${application.path}/../[module]"
- repoModules:
type: http
artifact: "http://mynexus/nexus/content/repositories/releases/com/myorg/[module]/[revision]/[module]-[revision].zip"
contains:
- com.myorg -> *
有了这个开发者和詹金斯首先在同一个仓库中搜索,看看是否有一个模块存在,如果没有,就去nexus仓库下载工件。
为了在 jenkins 中构建我的模块,我使用了这样的自定义 sh 脚本
#!/bin/bash
APPLICATION="myModule"
PLAY_PATH="/usr/local/play"
set –xe
$PLAY_PATH/play deps --sync
$PLAY_PATH/play build-module --require 1.2.3
VERSION=`grep self conf/dependencies.yml | sed "s/.*$APPLICATION //"`
echo "Sending $APPLICATION-$VERSION.zip to nexus repository"
curl --request POST --user user:passwd http://mynexus/nexus/content/repositories/releases/com/myorg/$APPLICATION/$VERSION/$APPLICATION-$VERSION.zip -F "file=@dist/$APPLICATION-$VERSION.zip" --verbose
使用此脚本,您可以在每个 jenkins 构建中将您的模块推送到 nexus。这不是我真正要做的。我只在构建发布时使用 jenkins 发布模块来推送它。对于一个版本,我有一个特殊的脚本
#!/bin/bash
APPLICATION="myModule"
PLAY_PATH="/usr/local/play"
set –xe
if [ -z "$RELEASE_VERSION" ]
then
echo "Parameter RELEASE_VERSION is mandatory"
exit 1
fi
if [ -z "$DEVELOPMENT_VERSION" ]
then
echo "Parameter DEVELOPMENT_VERSION is mandatory"
exit 1
fi
echo "Release version : $RELEASE_VERSION"
echo "Development version : $DEVELOPMENT_VERSION"
VERSION=`grep self conf/dependencies.yml | sed "s/.*$APPLICATION //"`
if [ "$RELEASE_VERSION" != "$VERSION" ]
then
echo "Release version $RELEASE_VERSION and play version $VERSION in dependencies.yml does not match : release failed"
exit 1
fi
REVISION=`svnversion .`
echo "Tag svn repository in revision $REVISION with version $VERSION"
svn copy -m "Version $VERSION" -r $REVISION http://mysvn/myRepo/$APPLICATION/trunk/ http://mysvn/myRepo/$APPLICATION/tags/$VERSION
echo "svn tag applied"
echo "Sending $APPLICATION-$VERSION.zip to nexus repository"
curl --request POST --user user:passwd http://mynexus/nexus/content/repositories/releases/com/myorg/$APPLICATION/$VERSION/$APPLICATION-$VERSION.zip -F "file=@dist/$APPLICATION-$VERSION.zip" --verbose
echo "$APPLICATION-$VERSION.zip sent to nexus repository"
echo "Update module to version $DEVELOPMENT_VERSION"
sed -i "s/self\(.*\)$VERSION/self\1$DEVELOPMENT_VERSION/g" conf/dependencies.yml
svn commit -m "Version $DEVELOPMENT_VERSION" conf/dependencies.yml
svn update
echo "Version $DEVELOPMENT_VERSION créée"
此脚本在我们的 svn 存储库中放置一个标签,将模块推送到 nexus 并更新 dependencies.yml 文件。
有了这个 jenkins 可以构建一个依赖于本地版本的模块的应用程序,而它还没有发布,然后可以通过从 nexus 存储库下载模块 artifcat 来构建应用程序。开发人员也是如此