Generate Jenkinsfile

The generate-jenkinsfile Maven plugin goal is, as before, bound to the package phase, so it will automatically download this file for normal builds:

mvn package
# or
mvn clean install # 'install' includes execution of 'package'

The alternative is to manually run this goal without having to wait on other parts of the build to complete:

cd my-service # Only in a multi-module project
mvn filegen:generate-jenkinsfile

Either of these commands will replace the Jenkinsfile with the new script content, and delete the existing Jenkinsfile-sandbox file since the single Jenkinsfile now contains the necessary logic to choose which environment-specific command to run.

The content will look similar to the following:

@Library(['scanhub', 'codeql-linux']) _ (1)

// Dynamically load the shared library code from Git
if (VAMF_ENVIRONMENT=="map-prod") { (2)
    library (identifier: 'jenkins-shared-libs@main', retriever: modernSCM(
            [$class: 'GitSCMSource',
             remote: 'https://coderepo.mobilehealth.va.gov/scm/ckm/jenkins-shared-libs.git',
             credentialsId: '2be89da0-461d-4af1-82ef-35f90dba4339']))
} else if (VAMF_ENVIRONMENT=="map-staging"){ (3)
    library (identifier: 'jenkins-shared-libs@main', retriever: modernSCM(
            [$class: 'GitSCMSource',
             remote: 'https://coderepo.mobilehealth.va.gov/scm/ckm/jenkins-shared-libs.git',
             credentialsId: '69ff7537-da06-4304-8821-9d970c8f8738']))
} else if (VAMF_ENVIRONMENT=="map-sandbox"){ (4)
    library (identifier: 'jenkins-shared-libs@main', retriever: modernSCM(
            [$class: 'GitSCMSource',
             remote: 'https://coderepo.mobilehealth.va.gov/scm/ckm/jenkins-shared-libs.git',
             credentialsId: '3f49e7de-bbca-40a5-b2a8-8c7baddba8ff']))
}
buildServiceProject() (5)
1 The @Library annotation imports the OIS scanning-related shared libraries.
2 If running on the Jenkins production instance
3 If running on the Jenkins SQA/Staging instance
4 If running on the Jenkins Sandbox instance
5 Call the Groovy shared library function to execute the build

Since each environment requires Git credentials identified by a different identifier, in order to download and run the Jenkins shared library code, the credentialsId is provided to each logical branch.