|
| 1 | +node ("docker-light") { |
| 2 | + def sourceDir = pwd() |
| 3 | + try { |
| 4 | + stage("Clean up") { |
| 5 | + step([$class: 'WsCleanup']) |
| 6 | + } |
| 7 | + stage("Checkout Code") { |
| 8 | + checkout scm |
| 9 | + } |
| 10 | + stage("Build & Test") { |
| 11 | + withSonarQubeEnv { |
| 12 | + mySonarOpts="/k:\"rosette-api-csharp-binding\" /d:sonar.host.url=${env.SONAR_HOST_URL} /d:sonar.login=${env.SONAR_AUTH_TOKEN}" |
| 13 | + |
| 14 | + if("${env.CHANGE_ID}" != "null"){ |
| 15 | + mySonarOpts = "$mySonarOpts /d:sonar.pullrequest.key=${env.CHANGE_ID}" |
| 16 | + } else { |
| 17 | + mySonarOpts = "$mySonarOpts /d:sonar.branch.name=${env.BRANCH_NAME}" |
| 18 | + } |
| 19 | + |
| 20 | + if ("${env.CHANGE_BRANCH}" != "null") { |
| 21 | + mySonarOpts="$mySonarOpts /d:sonar.pullrequest.base=${env.CHANGE_TARGET} /d:sonar.pullrequest.branch=${env.CHANGE_BRANCH}" |
| 22 | + } |
| 23 | + |
| 24 | + sh "docker run --rm \ |
| 25 | + --pull always \ |
| 26 | + --volume ${sourceDir}:/source \ |
| 27 | + mono:6 \ |
| 28 | + bash -c \"echo && \ |
| 29 | + echo [INFO] Updating package manager database. && \ |
| 30 | + apt-get update -qq && \ |
| 31 | + echo && \ |
| 32 | + echo [INFO] Installing required OS packages. && \ |
| 33 | + apt-get -qq install unzip default-jre-headless -y > /dev/null && \ |
| 34 | + echo && \ |
| 35 | + echo [INFO] Updating CA Certs file to address expired Lets Encrypt certificate. && \ |
| 36 | + echo [INFO] https://github.com/KSP-CKAN/CKAN/wiki/SSL-certificate-errors#removing-expired-lets-encrypt-certificates && \ |
| 37 | + sed -i 's,^mozilla/DST_Root_CA_X3.crt\$,!mozilla/DST_Root_CA_X3.crt,' /etc/ca-certificates.conf && \ |
| 38 | + echo && \ |
| 39 | + echo [INFO] Running update-ca-certificates && \ |
| 40 | + update-ca-certificates && \ |
| 41 | + echo && \ |
| 42 | + echo [INFO] Running cert-sync && \ |
| 43 | + cert-sync /etc/ssl/certs/ca-certificates.crt && \ |
| 44 | + echo && \ |
| 45 | + echo [INFO] Setting up Sonar Scanner && \ |
| 46 | + mkdir -p /opt/sonar-scanner && \ |
| 47 | + pushd /opt/sonar-scanner && \ |
| 48 | + curl --silent --output sonar-scanner.zip --location https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.15.0.80890/sonar-scanner-msbuild-5.15.0.80890-net46.zip && \ |
| 49 | + unzip -q sonar-scanner.zip && \ |
| 50 | + chmod a+x /opt/sonar-scanner/sonar-scanner-*/bin/* && \ |
| 51 | + pushd /source && \ |
| 52 | + echo && \ |
| 53 | + echo [INFO] Running Sonar Scanner Begin && \ |
| 54 | + mono /opt/sonar-scanner/SonarScanner.MSBuild.exe begin ${mySonarOpts} && \ |
| 55 | + echo && \ |
| 56 | + echo [INFO] Restoring the solution. && \ |
| 57 | + nuget restore rosette_api.sln && \ |
| 58 | + echo && \ |
| 59 | + echo [INFO] Running msbuild Release configuration. && \ |
| 60 | + msbuild /p:Configuration=Release rosette_api.sln /t:Rebuild && \ |
| 61 | + echo && \ |
| 62 | + echo [INFO] Running Sonar Scanner End && \ |
| 63 | + mono /opt/sonar-scanner/SonarScanner.MSBuild.exe end /d:sonar.login=\"${env.SONAR_AUTH_TOKEN}\" && \ |
| 64 | + echo && \ |
| 65 | + echo [INFO] Running unit tests && \ |
| 66 | + mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll\"" |
| 67 | + |
| 68 | + // TODO: Finish coverage data gathering for Sonar. |
| 69 | + ///opt/maven-basis/bin/mvn --batch-mode clean install sonar:sonar $mySonarOpts\"" |
| 70 | + //pushd /tmp |
| 71 | + //dotcover_version=2022.3.1 |
| 72 | + //curl --silent --location --output dotcover.tar.gz https://download.jetbrains.com/resharper/dotUltimate.2022.3.1/JetBrains.dotCover.CommandLineTools.linux-x64.2022.3.1.tar.gz |
| 73 | + //tar xzf dotcover.tar.gz |
| 74 | + } |
| 75 | + } |
| 76 | + postToTeams(true) |
| 77 | + } catch (e) { |
| 78 | + currentBuild.result = "FAILED" |
| 79 | + postToTeams(false) |
| 80 | + throw e |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +def postToTeams(boolean success) { |
| 85 | + def webhookUrl = "${env.TEAMS_PNC_JENKINS_WEBHOOK_URL}" |
| 86 | + def color = success ? "#00FF00" : "#FF0000" |
| 87 | + def status = success ? "SUCCESSFUL" : "FAILED" |
| 88 | + def message = "*" + status + ":* '${env.JOB_NAME}' - [${env.BUILD_NUMBER}] - ${env.BUILD_URL}" |
| 89 | + office365ConnectorSend(webhookUrl: webhookUrl, color: color, message: message, status: status) |
| 90 | +} |
0 commit comments