Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/jenkins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Mayhem for API on Jenkins'
on:
workflow_dispatch:

jobs:
jenkins-container-pipeline:
runs-on: ubuntu-22.04
container:
image: ghcr.io/jenkinsci/jenkinsfile-runner:master

steps:
- name: 'Checkout'
uses: actions/checkout@v1
- name: 'Run Jenkins job'
uses:
jenkinsci/jfr-container-action@master
with:
command: run
jenkinsfile: jenkins/Jenkinsfile
pluginstxt: jenkins/plugins.txt
env:
MAYHEM_URL: 'https://app.mayhem.security'
MAYHEM_TOKEN: ${{ secrets.MAYHEM_TOKEN }}

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ If your API server sends back stacktraces in the 500 Internal Server
Error (only do this in a test environment -- never in production!),
Mayhem for API will try to map issues it finds to the exact line of code
that triggered the issue.

## Example runs

- Github: see [this repo.](https://github.com/ForAllSecure/mapi-action-examples/actions/workflows/mapi.yml)
- Gitlab: see [https://gitlab.com/mayhem-forallsecure/mayhem-demo/-/jobs/10201916810](https://gitlab.com/mayhem-forallsecure/mayhem-demo/-/jobs/10201916810)
- Jenkins: copy the existing [Jenkinsfile](https://github.com/ForAllSecure/mapi-action-examples/blob/jenkins-example/jenkins/Jenkinsfile) into a new pipeline configuration and run the pipeline. Make sure to install the [plugins](https://github.com/ForAllSecure/mapi-action-examples/blob/jenkins-example/jenkins/plugins.txt)
19 changes: 14 additions & 5 deletions Jenkinsfile → jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// First job
pipeline {
agent any
agent {
docker { image 'python:3.9' }
}

environment {
MAYHEM_URL = 'https://app.mayhem.security'
}

stages {
stage('Build') {
steps {
echo 'Building..'
sh '''
cd /workspace
pip install -r requirements.txt
'''
}
Expand All @@ -15,6 +22,7 @@ pipeline {
steps {
echo 'Building..'
sh '''
cd /workspace
FASTAPI_ENV=test python3 -m coverage run -m uvicorn src.main:app &
'''
}
Expand All @@ -27,9 +35,9 @@ pipeline {
sh '''
curl -Lo mapi ${MAYHEM_URL}/cli/mapi/linux-musl/latest/mapi && chmod +x mapi
'''
withCredentials([string(credentialsId: 'MAPI_TOKEN', variable: 'MAPI_TOKEN')]) {
withCredentials([string(credentialsId: 'MAYHEM_TOKEN', variable: 'MAYHEM_TOKEN')]) {
sh '''
./mapi login ${MAPI_TOKEN}
./mapi login ${MAYHEM_TOKEN}
./mapi run forallsecure-demo/mapi-action-examples/fastapi auto "http://localhost:8000/openapi.json" --url "http://localhost:8000/" --junit junit.xml --sarif mapi.sarif --html mapi.html
'''
}
Expand All @@ -38,7 +46,7 @@ pipeline {
sh 'pgrep python3 | xargs kill || true'

/* Generate coverage report */
sh 'python3 -m coverage xml -o coverage.xml'
sh 'python3 -m coverage xml -o coverage.xml || true'
}
}
}
Expand All @@ -54,7 +62,8 @@ pipeline {
junit 'junit.xml'
recordIssues(enabledForFailure: true,
tool: sarif(pattern: 'mapi.sarif'))
cobertura coberturaReportFile: 'coverage.xml', onlyStable: 'false'
recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'coverage.xml']],
sourceCodeRetention: 'LAST_BUILD')
}
}
}
7 changes: 7 additions & 0 deletions jenkins/plugins.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
git
docker
docker-pipeline
warnings
junit
coverage
credentials
Loading