CodeScan in Github Actions using the SFDX Plugin
Integrating CodeScan into your Github pipeline is easy with our sfdx plugin. There are only a few lines to add to your .YML file to run CodeScan when a build is triggered.
Note: The following is based on a docker pipeline with Java and Node installed in the container.
First, we'll need to add your CodeScan token as a variable we can access in our .YML file.
Open your project and navigate to Repository Settings > Repository Variables (you'll find this under Pipelines).
Add your token with the name codescan_token and check the Secured box. To learn how to generate a token, see HERE.
Now you'll be able to access this variable by using $codescan_token in your .YML file.
Add the following into your .YML file in the workflow:
You will need to replace the placeholder variables (in bold) in the env section of the script with your Project Key and Organization Key.
The branch names and comparisons are set by the following parameters:
sonar.pullrequest.key
: The pull request number
sonar.pullrequest.base
: The comparison branch for pull request type branches
sonar.pullrequest.branch
: The name of the branch
The conditionals in your script determine what triggered the build and by defining the branch type, name and target using Bitbucket pipeline's built in variables, you can create a project that gives you visibility on your new code while allowing you to plan your refactoring effort.
By default, the CodeScan SFDX plugin will fail if the Quality Gate fails. If you would prefer that the build passes despite the quality gate, use the --nofail tag when calling sfdx codescan:run.
You can find a complete list of flags and examples on our npm plugin page.
Last updated