Adapting the pipeline script to use a custom script - Cloud

Talend Software Development Life Cycle for Cloud - Best Practices Guide

Version
Cloud
Language
English (United States)
Product
Talend Cloud
Module
Talend Artifact Repository
Talend Management Console
Talend Studio
Content
Administration and Monitoring
Deployment
Design and Development

If you want to execute specific CommandLine commands before building your project, you might want to edit the pipeline script provided by Talend to define and execute this custom script.

Procedure

  1. Open the Talend_Pipeline configuration page and go to the Script editor.
  2. To add your custom script, add a stage before the 'Build, Test and Publish artifacts to artifact repository' stage defined in the default script provided by Talend in order to write your own custom script.

    Example

    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"
                }
        }

    allows you to write a script that will create a project named CICD_PROJ, to log in the project, to import Job archives, to regenerate all .pom files and to log off the project.

    Note:
    • The example is adapted for Unix environments. If you are using Windows, replace sh with bat in the example.
    • The -DexecuteRawScript parameter is set to false by default, which means that all commands are embedded between logon and logoff commands. If set to true, the script will be executed exactly as it is. In that example the project needs to be created before importing items so it is set to true.

    Example

    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.*""
                }
        }

    allows you to write a script that will regenerate all .pom files of the projects with a name that start with CICD* and log off these projects.

    Note:
    • The example is adapted for Unix environments. If you are using Windows, replace sh with bat in the example.
    • The -DprojectFilter parameter allows you to filter on the project you want to build.
  3. Click Save to take your changes into account.