Skip to content

Commit 88bce99

Browse files
author
Prabhu Subramanian
authored
Updated gitlab docs (#54)
1 parent 47bb3d3 commit 88bce99

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

docs/integrations/gitlab.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
## Integration with Gitlab CI
1+
# Integration with GitLab CI
22

3-
ShiftLeft Scan scanning is available for all GitLab CI users including the free users. Simply add the below section to your `.gitlab-ci.yml` file
3+
ShiftLeft Scan is available for all GitLab CI users including the free users. In addition, it is possible to configure scan to add notes/comments to merge requests.
4+
5+
Simply add the below section to your `.gitlab-ci.yml` file
46

57
```yaml
68
job:
@@ -22,6 +24,8 @@ scan:
2224
name: shiftleft/sast-scan
2325
script:
2426
- scan --src ${CI_PROJECT_DIR} --type credscan,python,depscan --out_dir ${CI_PROJECT_DIR}/reports
27+
rules:
28+
- when: always
2529
artifacts:
2630
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
2731
paths:
@@ -42,9 +46,56 @@ scan:
4246
name: shiftleft/sast-scan
4347
script:
4448
- scan --build --src ${CI_PROJECT_DIR} --type credscan,java,depscan --out_dir ${CI_PROJECT_DIR}/reports
49+
rules:
50+
- when: always
51+
artifacts:
52+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
53+
paths:
54+
- $CI_PROJECT_DIR/reports/
55+
when: always
56+
```
57+
58+
## Merge Request comment feature
59+
60+
61+
Set the following Repository variables to enable merge request notes/comment feature.
62+
63+
- `SCAN_ANNOTATE_PR` to `true`
64+
- GITLAB_TOKEN - Personal access token belonging to a user with `api` scope. Best is to create a separate build user and a token
65+
- GITHUB_TOKEN - To enable dependency and licence scanning
66+
67+
Below are the full configuration and example screenshots:
68+
69+
```yaml
70+
variables:
71+
GITHUB_TOKEN: $GITHUB_TOKEN
72+
GITLAB_TOKEN: $GITLAB_TOKEN
73+
SCAN_ANNOTATE_PR: "true"
74+
75+
scan:
76+
stage: test
77+
image:
78+
name: shiftleft/sast-scan:gl-insights
79+
script:
80+
- scan --src ${CI_PROJECT_DIR} --type python,depscan --out_dir ${CI_PROJECT_DIR}/reports
81+
rules:
82+
- when: always
4583
artifacts:
4684
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
4785
paths:
4886
- $CI_PROJECT_DIR/reports/
4987
when: always
5088
```
89+
90+
![GitLab Merge Request](img/gitlab-mr.png)
91+
92+
To customize the message used for the comment, create a .sastscanrc file in the repo as suggested [here](tips.md) with the below config.
93+
94+
```json
95+
{
96+
"PR_COMMENT_TEMPLATE": "## ShiftLeft Scan Summary\n%(summary)s\n## Recommendation\n%(recommendation)s\n"
97+
}
98+
```
99+
100+
- summary - Summary Table
101+
- recommendation - One liner recommendation string (Hardcoded for now)

docs/integrations/img/gitlab-mr.png

176 KB
Loading

0 commit comments

Comments
 (0)