如何使用Play自定义模块和持续集成

Lad*_*ein 8 build-automation continuous-integration dependency-management playframework

如何在CI系统中设置Play应用程序和(自定义)Play模块的构建,以便在模块构建良好时,构建将模块工件安装在本地存储库中和/或将它们部署到远程存储库,并且应用程序使用该存储库中的工件?

该解决方案也适用于在本地工作的开发人员.

我正在使用Jenkins,并且无论如何我都会遇到麻烦.

在我详细阐述我遇到的所有问题之前,我会等待,因为它很费劲,也许其他人可以提供他们如何做到这一点.

Seb*_*ron 6

我有一个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 -> *
Run Code Online (Sandbox Code Playgroud)

这个开发人员和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
Run Code Online (Sandbox Code Playgroud)

使用此脚本,您可以在每个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"
Run Code Online (Sandbox Code Playgroud)

此脚本在我们的svn存储库中放置一个标记,将模块推送到nexus并更新dependencies.yml文件.

有了这个jenkins可以构建一个应用程序,它取决于模块的本地版本,而不是发布,之后可以通过从nexus存储库下载模块artifcat来构建应用程序.对开发人员来说也是如此