|
| 1 | +#!/usr/bin/env groovy |
| 2 | + |
| 3 | +codeqlUrl = "https://github.com/github/codeql-action/releases/latest/download/codeql-bundle-linux64.tar.gz" |
| 4 | +outputFile = "results.serif" |
| 5 | +databaseName = "javascript-db" |
| 6 | +scmTargetPath = "api-client-js" |
| 7 | +repo = "git@github.com:bitbar/cloud-api-client-js.git" |
| 8 | +credentialsId = "bitbar-dev-ssh" |
| 9 | +githubApiCredentialsId = "4235c5e0-e60b-4c7d-8816-9508e60f484d" |
| 10 | +branch = "master" |
| 11 | +language = "javascript" //It's for both javascript and typescript |
| 12 | + |
| 13 | +properties( |
| 14 | + [ |
| 15 | + buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '50', numToKeepStr: '50')), |
| 16 | + disableConcurrentBuilds(), |
| 17 | + pipelineTriggers([pollSCM("@weekly")]), |
| 18 | + ] |
| 19 | +) |
| 20 | + |
| 21 | +node('linux && docker') { |
| 22 | + try { |
| 23 | + stage("Repo preparations") { |
| 24 | + def scmVars = checkout([ |
| 25 | + $class : 'GitSCM', |
| 26 | + branches : [[name: branch]], doGenerateSubmoduleConfigurations: false, |
| 27 | + extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: scmTargetPath]], |
| 28 | + userRemoteConfigs: [[credentialsId: credentialsId, url: repo]] |
| 29 | + ]) |
| 30 | + env.GIT_REPO_NAME = scmVars.GIT_URL.replaceFirst(/^.*:(.*)\.git$/, '$1') |
| 31 | + } |
| 32 | + |
| 33 | + stage('Init codeQL') { |
| 34 | + init() |
| 35 | + } |
| 36 | + |
| 37 | + stage('CodeQL analyze') { |
| 38 | + analyze() |
| 39 | + } |
| 40 | + |
| 41 | + stage('CodeQL results publishing') { |
| 42 | + publish() |
| 43 | + } |
| 44 | + |
| 45 | + } finally { |
| 46 | + stage('notification') { |
| 47 | + notification() |
| 48 | + cleanWs() |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +def init() { |
| 54 | + sh("curl -sSL ${codeqlUrl} -o code-ql.tar.gz") |
| 55 | + sh("tar -xvzf ./code-ql.tar.gz") |
| 56 | +} |
| 57 | + |
| 58 | +def analyze() { |
| 59 | + docker.image("node:14.21.3-bullseye").inside("-u 0:0") { |
| 60 | + sh("${WORKSPACE}/codeql/codeql database create ${databaseName} --language=${language} --source-root=${scmTargetPath}") |
| 61 | + sh("${WORKSPACE}/codeql/codeql database analyze ${databaseName} --format=sarif-latest --output=${outputFile}") |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +def publish() { |
| 66 | + withCredentials([string(credentialsId: githubApiCredentialsId, variable: 'GITHUB_TOKEN')]) { |
| 67 | + sh("${WORKSPACE}/codeql/codeql github upload-results --repository=${env.GIT_REPO_NAME} --ref=refs/heads/${branch} --checkout-path=${WORKSPACE}/${scmTargetPath} --sarif=${outputFile}") |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +def notification() { |
| 72 | + def text = "Scan <${env.BUILD_URL}|${env.JOB_NAME}[${env.BUILD_NUMBER}]>\n Finished with result ${currentBuild.currentResult}" |
| 73 | + colorCode = currentBuild.currentResult == 'SUCCESS' ? '#00FF00' : '#FF0000' |
| 74 | + slackSend color: colorCode, teamDomain: 'smartbear', channel: "bitbar-frontend", message: text, tokenCredentialId: |
| 75 | + 'SLACK_BACKEND_INTEGRATION_TOKEN' |
| 76 | +} |
0 commit comments