corda/.ci/dev/pr-code-checks/Jenkinsfile
2024-06-19 11:08:13 +01:00

112 lines
3.8 KiB
Groovy

@Library('corda-shared-build-pipeline-steps')
import groovy.transform.Field
import static com.r3.build.BuildControl.killAllExistingBuildsForJob
import com.r3.build.utils.PipelineUtils
@Field
PipelineUtils pipelineUtils = new PipelineUtils(this)
killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
pipeline {
agent { label 'standard' }
options {
timestamps()
timeout(time: 3, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '14', artifactDaysToKeepStr: '14'))
}
/*
* List environment variables in alphabetical order
*/
environment {
SNYK_API_TOKEN = credentials('c4-os-snyk-api-token-secret')
C4_OS_SNYK_ORG_ID = credentials('c4-os-snyk-org-id')
ARTIFACTORY_CREDENTIALS = credentials('artifactory-credentials')
CORDA_ARTIFACTORY_PASSWORD = "${env.ARTIFACTORY_CREDENTIALS_PSW}"
CORDA_ARTIFACTORY_USERNAME = "${env.ARTIFACTORY_CREDENTIALS_USR}"
CORDA_USE_CACHE = "corda-remotes"
JAVA_HOME = "/usr/lib/jvm/java-17-amazon-corretto"
}
stages {
stage('Detekt check') {
steps {
authenticateGradleWrapper()
sh "./gradlew --no-daemon clean detekt"
}
}
stage('Compilation warnings check') {
steps {
sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=true compileAll"
}
}
stage('Snyk Delta') {
agent { label 'standard' }
steps {
authenticateGradleWrapper()
snykDeltaScan(env.SNYK_API_TOKEN, env.C4_OS_SNYK_ORG_ID)
}
}
stage('Scan API Changes (new plugin)') {
steps {
catchError(message: "API Scan failed - breaking changes detected", stageResult: 'FAILURE') {
sh "./gradlew apiDiff"
}
}
post {
success {
script {
String commentText = """\
|Scanning for breaking API changes introduced by this PR\n
|Scan Succeeded\n
|\n
|Please check if there are any new API additions as these will need to be updated before this PR is merged
|```\n
|./gradlew cementApi\n
|```
""".stripMargin()
githubPRComment(commentText, "Scanning for breaking API changes introduced by this PR")
}
}
failure {
script {
String commentText = """\
|Scanning for breaking API changes introduced by this PR\n
|Scan Failed: ${env.BUILD_URL}\n
|If the breaking changes are intentional, run `./gradlew cementApi` and get approval from the Corda team leads.
""".stripMargin()
githubPRComment(commentText, "Scanning for breaking API changes introduced by this PR")
}
}
}
}
stage('No API change check') {
steps {
sh "./gradlew --no-daemon generateApi"
sh ".ci/check-api-changes.sh"
}
}
stage('Deploy Nodes') {
steps {
sh "./gradlew --no-daemon jar deployNodes"
}
}
}
post {
cleanup {
deleteDir() /* clean up our workspace */
}
}
}
def githubPRComment(String commentText, String pattern) {
Long userCommentId = pipelineUtils.getUserCommentIdMatchingPattern(pattern)
userCommentId == null ? pipelineUtils.addGitHubComment(commentText) : pipelineUtils.editGitHubComment(commentText, userCommentId)
}