Jenkins declarative pipeline: Execute stage when file has changed or a new branch was created
The following pipeline did the trick for me:
pipeline { agent any stages { stage('checkout') { steps { checkout scm } } stage('build & push container') { when { anyOf { changeset 'Dockerfile' expression { return currentBuild.number == 1 } } } steps { echo "Building..." } } }}