CodeScan with Windows Agents

Requirements

You will need:

  • Jenkins

  • Salesforce CLI

  • Git

Add Environment Variables

Setup Jenkins

  1. In Jenkins, create a credential containing your CodeScan token (learn how to find this 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:

    • Your credential_name should be the name of the credential you created.

    • my_project should be the project key you would like to assign to your project.

    • my_organization should be your Organization Key (learn how to find this here).

      • The --server=yourserveraddress flag is required for self hosted instances.

node {

    stage('Pull from Git') {

      git 'https://wherever.com/me/my-repo.git'

    }

    withCredentials([string(credentialsId: 'credential_name', variable: 'codescan_token')]) {
stage('CodeScan') {
sh '''
echo y|sfdx plugins:install sfdx-codescan-plugin
      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