Requirements
You will need:
- Jenkins
- Salesforce CLI
- Git
Add Environment Variables
- In user environment Path variable, add the SalesForce CLI and Git bin directories.
- In the System environment Path variable add the Git\cmd, Git\usr\bin, and Salesforce CLI\bin directories.
Setup Jenkins
- In Jenkins, create a credential containing your CodeScan token (learn how to find this here).
- Create a new Pipeline.
- 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=
your_server_address
flag is required for self hosted instances.
- The --server=
-
- Your
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 $?
'''
}
}
}
- Run the pipeline. If everything is set up correctly and your Quality Gate passes, you will be able to see you pipeline pass.
- If your Quality Gate fails, you will see the error in the CodeScan stage of the build.