CodeScan with Linux/Unix Agents

To fail a Jenkins job based on the outcome of your Quality gate takes a bit of setting up but is a great way to track the health of your projects from Jenkins. This is achieved with our SFDX plugin.


You will need:

  • Jenkins

Setup Jenkins

  1. In Jenkins, create a credential containing your CodeScan security token (learn how to find security token here).

  2. Create a new Pipeline.

  3. In the Pipeline script section you will need to paste in the code with the highlighted variables changed, these are:

node {

    stage('Pull from Git') {

      git ''


    withCredentials([string(credentialsId: 'credential_name', variable: 'codescan_token')]) {
    stage('CodeScan') {
      sh '''
        export PATH="$(pwd)/.sfdx-install/bin/:$PATH"
        if [ ! -f .sfdx-install/bin/sfdx ]; then
          mkdir .sfdx-install
          wget -q -O .sfdx-install/sfdx.tar.xz
          tar xJf .sfdx-install/sfdx.tar.xz -C .sfdx-install --strip-components 1
          echo y|sfdx plugins:install sfdx-codescan-plugin
sfdx plugins:update
        sfdx codescan:run --token=$codescan_token --projectkey=my_project --organization=my_organization
        exit $?
      '''       }
   } }
  1. Run the pipeline. If everything is set up correctly and your Quality Gate passes, you will be able to see you pipeline pass.

  2. If your Quality Gate fails, you will see the error in the CodeScan stage of the build.

Last updated