我在詹金斯中有一个从开发到生产都运行良好的设置。
首先是自定义模块存储库的 dependency.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 -> *
有了这个,开发人员和 jenkins 首先在同一个存储库中搜索以查看模块是否存在,如果不存在,则转到 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 并更新 dependency.yml 文件。
有了这个jenkins可以构建一个应用程序,该应用程序依赖于模块的本地版本,而该模块尚未发布,之后可以通过从nexus存储库下载模块artifcat来构建应用程序。对于开发者来说也是一样的