 |trigger:
    |  batch: true
    |  branches:
    |    include:
    |    - tests/*
    |
    |variables:
    |  talend_project_name: project1    # this is available to all Jobs
    |
    |stages:
    |- stage: talend_build_jobs
    |  jobs:
    |  - job: Mavend_Build
    |
    |    pool:
    |      vmImage: 'ubuntu-18.04'
    |
    |    continueOnError: false
    |
    |    steps:
    |      - bash: |
 1  |          repoUri=$REPO_URI
 2  |          #echo "Build.Repository.Uri: $repoUri"
 3  |          pattern='https://(.*)@dev\.azure\.com/(.*)/_git/.*'
 4  |          [[ $repoUri =~ $pattern ]]
 5  |          user=${BASH_REMATCH[1]}
 6  |          org_prj=${BASH_REMATCH[2]}
 7  |
 8  |          currentBuildId=$BUILD_ID
 9  |          previousBuildId=$(( currentBuildId - 1))
 10 |
 11 |          api_url="https://dev.azure.com/${org_prj}/_apis/build/builds/$currentBuildId/changes?api-version=5.1"
 12 |          echo "currentBuildId= '$currentBuildId'"
 13 |          echo "api_url= '$api_url'"
 14 |
 15 |          total_commits=$(curl -s -u $user:$SYSTEM_ACCESSTOKEN $api_url | jq .count)
 16 |          #echo "Changes for this build # $currentBuildId"
 17 |          #curl -s -u $user:$SYSTEM_ACCESSTOKEN $api_url | jq .
 18 |
 19 |          nb_commits=$total_commits
 20 |          echo "Number of pushed commits since last build: $nb_commits"
 21 |          file_list=$(git diff --name-only @~${nb_commits})
 22 |          echo ">> List of modified files in this/these commit(s):"
 23 |          echo "========================================="
 24 |          echo "$file_list"
 25 |          echo "========================================="
 26 |          module_list=""
 27 |          if [ "$(echo "$file_list" | grep "$(talend_project_name)/process")" ]; then
 28 |             echo "- List of jobs that have changed:"
 29 |             for job_type in process process_mr process_storm; do
 30 |               for job in `echo "$file_list" | grep "$(talend_project_name)/$job_type" | grep "\.item$" | cut -d "/" -f 3- | cut -d "." -f -2`; do module_list+=",jobs/$job_type/$job" && echo "  $job"; done
 31 |             done
 32 |             module_list=$(echo $module_list | cut -c2-)
 33 |             module_list=$(echo $module_list | tr '[:upper:]' '[:lower:]')
 34 |             echo "========================================="
 35 |             echo "Number of di job: " `echo $module_list | grep -o "process/" | wc -l`
 36 |             echo "Number of BD batch job: " `echo $module_list | grep -o "process_mr/" | wc -l`
 37 |             echo "Number of BD Streaming job: " `echo $module_list | grep -o "process_storm/" | wc -l`
 38 |             echo "========================================="
 39 |             echo "- List of modules to build:"
 40 |             echo "$module_list"
 41 |          else
 42 |             echo "- No jobs have changed."
 43 |          fi
 44 |          echo "##vso[task.setvariable variable=module_list]$module_list"
 45 |        displayName: 'Find list of jobs (if any) that changed for the this build.'
 46 |        env:
 47 |          SYSTEM_ACCESSTOKEN: $(System.AccessToken)
 48 |          REPO_URI: $(Build.Repository.Uri)
 49 |          BUILD_ID: $(Build.BuildId)
 50 |
 51 |      - bash: |
 52 |          echo ">> Maven parameter: '-pl $MODULE_LIST'"
 53 |        displayName: 'Build Job'
 54 |        condition: ne(variables['module_list'], '')
    |