// Comments pipeline { agent { label 'bellatrix' } options { disableConcurrentBuilds() timestamps() gitlabBuilds(builds: ["Build", "Test"]) } stages { stage ('Verify Parameters') { steps { echo 'Verify Parameters' echo "Base URL is ${JENKINS_URL}" echo "Git Branch is ${GIT_BRANCH}" echo "Git Commit is ${GIT_COMMIT}" echo "Git URL is ${GIT_URL}" echo "GitLab Act is ${env.gitlabActionType}" script { if ("MERGE".equals(env.gitlabActionType)) { echo "GitLab src branch is ${env.gitlabSourceBranch}" echo "GitLab tar branch is ${env.gitlabTargetBranch}" // GitLab-Jenkins pugin integration is lacking to perform the merge by itself // Doing it manually --> it may have merge conflicts sh "git merge --ff origin/${env.gitlabTargetBranch}" sh "git log -n1" } } } } stage ('Build') { steps { gitlabCommitStatus("Build") { sh "gcc src/test1.c -o bin/test1" sh "gcc src/test2.c -o bin/test2" sh "cppcheck --enable=warning --force --xml --xml-version=2 src 2> cppcheck.xml" } } } stage ('Test') { steps { gitlabCommitStatus("Test") { sh "./bin/test1" sh "./bin/test2" } } } } post { always { script { if(fileExists('cppcheck.xml')) { archiveArtifacts artifacts: 'cppcheck.xml' } } } success { script { if ("MERGE".equals(env.gitlabActionType)) { echo "This is a MERGE event" def msg = "OAI build #" + BUILD_ID + " passed" echo "$msg" addGitLabMRComment comment: msg def message = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ")" echo "$message" addGitLabMRComment comment: message } } } failure { script { if ("MERGE".equals(env.gitlabActionType)) { echo "This is a MERGE event" def message = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ")" addGitLabMRComment comment: message } } } } }