// set the build options according to the Type of build def (options,maven_local_repo_path,maven_settings_file) = ['','',''] def maven_jdk = 'OpenJDK 8' if (params.Type == 'SNAPSHOT-DRY-RUN') { echo "Configure Maven for SNAPSHOT-DRY-RUN artifacts" options = '' maven_local_repo_path = "${env.HOME}/local-snapshots" maven_settings_file = "${env.HOME}/.m2/jenkins-shapshots-dry-run-settings.xml" maven_settings_file = "${env.HOME}/.m2/settings.xml" //TODO: to remove, just for testing } if (params.Type == 'SNAPSHOT') { echo "Configure Maven for SNAPSHOT artifacts" options = '' maven_local_repo_path = "${env.HOME}/local-snapshots" maven_settings_file = "${env.HOME}/.m2/jenkins-shapshots-settings.xml" maven_settings_file = "${env.HOME}/.m2/settings.xml" //TODO: to remove, just for testing } if (params.Type == 'RELEASE-DRY-RUN') { echo "Configure Maven for RELEASE-DRY-RUN artifacts" options = '' maven_local_repo_path = "${env.HOME}/local-releases" maven_settings_file = "${env.HOME}/.m2/jenkins-releases-dry-run-settings.xml" maven_settings_file = "${env.HOME}/.m2/settings.xml" //TODO: to remove, just for testing } if (params.Type == 'RELEASE') { echo "Configure Maven for RELEASE artifacts" options = '' maven_local_repo_path = "${env.HOME}/local-releases" maven_settings_file = "${env.HOME}/.m2/jenkins-releases-settings.xml" maven_settings_file = "${env.HOME}/.m2/settings.xml" //TODO: to remove, just for testing } echo "Use settings file at ${maven_settings_file}" echo "Use local repo at ${maven_local_repo_path}" pipeline { // see https://jenkins.io/doc/book/pipeline/syntax/#agent agent { label 'pipeline-agent' } // see https://jenkins.io/doc/book/pipeline/syntax/#environment environment { JOB_OPTIONS = "${options}" MAVEN_LOCAL_REPO = "${maven_local_repo_path}" } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters parameters { choice(choices: ['SNAPSHOT-DRY-RUN', 'SNAPSHOT', 'RELEASE-DRY-RUN', 'RELEASE'], description: 'The type of artifacts the build is expected to generate', name: 'Type') } //see https://jenkins.io/doc/book/pipeline/syntax/#stages stages { stage('clean up before starting') { script { echo "Create a fresh local repository" rm -rf $MAVEN_LOCAL_REPO mkdir -p $MAVEN_LOCAL_REPO echo "Done with local repository" } } stage('build core components') { steps { withMaven(jdk: "${maven_jdk}", mavenLocalRepo: "${maven_local_repo_path}", mavenSettingsFilePath: "${maven_settings_file}") { build 'maven-parent' build 'gcube-bom' build 'authorization-common-library' build 'gxRest' } script { echo "Done with core components" } } } } // post-build actions post { always { echo 'This will always run' } success { echo 'This will run only if successful' } failure { echo 'This will run only if failed' } unstable { echo 'This will run only if the run was marked as unstable' } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } } }