プロジェクトをビルドする前に特定のCommandLineコマンドを実行する場合は、Talendが提供するパイプラインスクリプトを編集し、そのカスタムスクリプトを定義して実行できるようにするとよいでしょう。
手順
- Talend_Pipeline設定ページを開き、[Script] (スクリプト)エディターに移動します。
-
カスタムスクリプトを追加する場合は、自分のカスタムスクリプトを書けるよう、Talendが提供するデフォルトスクリプトで定義されている'Build, Test and Publishs artifacts to artifact repository'ステージの前にステージを追加します。
例え
stage ('Create project and import items') { sh "rm -rf CICD" sh "rm -f script.txt" sh "echo \"initLocal\" >> script.txt" sh "echo \"createProject -pn CICD_PROJ -pd 'CI project' -pl java -pa jobbuilder@talend.com\" >> script.txt" sh "echo \"logonProject -pn CICD_PROJ -ul 'jobbuilder@talend.com' -gt\" >> script.txt" sh "echo \"importItems /Users/Talend/MyParentBigJob_0.1.zip -o\" >> script.txt" sh "echo \"importItems /Users/Talend/MyChildJob_0.1.zip -o\" >> script.txt" sh "echo \"regenerateAllPoms\" >> script.txt" sh "echo \"logoffProject\" >> script.txt" withMaven( // Maven installation declared in the Jenkins "Global Tool Configuration" maven: 'M3', // Maven settings.xml file defined with the Jenkins Config File Provider Plugin // Maven settings and global settings can also be defined in Jenkins Global Tools Configuration mavenSettingsConfig: MAV_SETTINGS, mavenOpts: '-Dlicense.path=<PathToDirectory>/license/license -Dupdatesite.path=http://company/updatesite -Dpatch.path=http://company/updatesite/patch/<patch_archive_name>.zip') { // Run the maven build sh "mvn org.talend.ci:builder-maven-plugin:<version>:executeScript -DscriptFile=${env.WORKSPACE}/script.txt -DexecuteRawScript=true" } }
CICD_PROJという名前のプロジェクトを作成するスクリプトを書けるようになり、それによってプロジェクトへのログイン、ジョブアーカイブのインポート、全.pomファイルの再生成、プロジェクトからのログオフが可能になります。
注:- サンプルはUnix環境に合わせてあります。Windowsをお使いの場合は、サンプル内のshをbatに置き換えてください。
- DexecuteRawScriptパラメーターはデフォルトでfalseに設定されていますが、これはすべてのコマンドがlogonコマンドとlogoffコマンドの間に組み込まれていることを意味します。trueに設定されていれば、スクリプトはそのまま実行されます。この例ではアイテムをインポートする前にプロジェクトを作成する必要があるので、trueに設定されています。
例え
stage ('Regenerate all poms') { sh "echo \"regenerateAllPoms\" >> script.txt" withMaven( // Maven installation declared in the Jenkins "Global Tool Configuration" maven: 'M3', // Maven settings.xml file defined with the Jenkins Config File Provider Plugin // Maven settings and global settings can also be defined in Jenkins Global Tools Configuration mavenSettingsConfig: MAV_SETTINGS, mavenOpts: '-Dlicense.path=<PathToDirectory>/license/license -Dupdatesite.path=http://company/updatesite -Dpatch.path=http://company/updatesite/patch/<patch_archive_name>.zip') { // Run the maven build sh "mvn org.talend.ci:builder-maven-plugin:<version>:executeScript -DscriptFile=${env.WORKSPACE}/script.txt -DprojectFilter="CICD.*"" } }
CICD*で始まる名前のプロジェクトの.pomファイルをすべて再生成し、そのプロジェクトをログオフするスクリプトが書けるようになります。
注:- サンプルはUnix環境に合わせてあります。Windowsをお使いの場合は、サンプル内のshをbatに置き換えてください。
- -DprojectFilterパラメーターを使えば、ビルドするプロジェクトにフィルターを適用できます。
- [Save] (保存)をクリックして変更内容を反映させます。