title: Only build projects if something has changed
body: <p>We want to split up our project into smaller pieces. Our current CI process goes through a short test phase and then runs a deployment script. However, if nothing has changed in one of the sub project, we do not want to go through the build for this.</p>
  
  <p>Jenkins without pipelines supports exclusions in the SCM configuration (we use git) and based on this, you can configure a specific job to run. However, when using a pipeline, how can I know, if I should build this part or not? How do I get access to the paths that were affected by the last push?</p>
  
  <p>At the moment our script is very simple, and we would like to keep it as simple as possible.</p>
  
  <p>We were playing around with the <a href="https://jenkins.io/doc/book/pipeline/syntax/#scripted-pipeline" rel="nofollow noreferrer">scripted</a> and the <a href="https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline" rel="nofollow noreferrer">declarative</a> syntax, but could not find a good solution.</p>
  
  <p>Declarative:</p>
  
  <pre><code>#!groovy​
  pipeline {
      agent any
      tools {
          nodejs '8.1'
      }
      stages {
          stage('Checkout') {
              steps {
                  checkout scm
              }
          }
  
          # Only continue, if something has changed
  
          stage('Install') {
              steps {
                  sh 'npm install'
              }
          }
  
          stage('Test') {
              steps {
                  sh 'npm run test-jenkins'
              }
              post {
                  always {
                      junit "artifacts/test/report.xml"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Scripted:</p>
  
  <pre><code>#!groovy​
  node {
      def nodejs = tool name: '8.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
      env.PATH = "${nodejs}/bin:${env.PATH}"
  
      stage('Checkout') {
          checkout scm
      }
  
      # Only continue, if something has changed
  
  
      stage('Install') {
          sh 'npm install'
      }
  
      stage('Test') {
          try {
              sh 'npm run test-jenkins'
          } finally {
              junit "artifacts/test/report.xml"
          }
      }
  }
  </code></pre>