Jenkins Integration
This guide shows how to integrate x-fidelity into your Jenkins pipelines.
Basic Pipeline Configuration
Create Jenkinsfile
in your repository:
pipeline {
agent {
docker {
image 'node:18'
}
}
stages {
stage('x-fidelity') {
steps {
sh '''
yarn global add x-fidelity
export PATH="$PATH:$(yarn global bin)"
xfidelity . --configServer https://config-server.example.com
'''
}
environment {
OPENAI_API_KEY = credentials('openai-api-key')
XFI_SHARED_SECRET = credentials('xfi-shared-secret')
}
}
}
}
Advanced Configuration
With OpenAI Integration
stage('x-fidelity') {
steps {
sh 'xfidelity . -o true'
}
environment {
OPENAI_API_KEY = credentials('openai-api-key')
OPENAI_MODEL = 'gpt-4'
}
}
With Local Config
stage('x-fidelity') {
steps {
sh 'xfidelity . --localConfigPath ./config'
}
}
With Custom Archetype
stage('x-fidelity') {
steps {
sh 'xfidelity . --archetype java-microservice'
}
}
Jenkins Specific Features
Parallel Execution
stage('x-fidelity') {
parallel {
stage('node-fullstack') {
steps {
sh 'xfidelity . --archetype node-fullstack'
}
}
stage('java-microservice') {
steps {
sh 'xfidelity . --archetype java-microservice'
}
}
}
}
Artifacts
post {
always {
archiveArtifacts artifacts: 'results.json', fingerprint: true
junit 'results.xml'
}
}
Notifications
post {
failure {
emailext (
subject: "x-fidelity Check Failed: ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: "Check console output at ${env.BUILD_URL}",
to: 'team@example.com'
)
}
}
Environment Variables
Set these in Jenkins credentials:
openai-api-key
: For OpenAI integrationxfi-shared-secret
: For config server authenticationconfig-server-url
: Your config server URL
Best Practices
- Secrets Management: Use Jenkins credentials for sensitive data
- Workspace Cleanup: Clean workspace before and after builds
- Versioning: Pin dependency versions
- Error Handling: Add proper error handling
- Notifications: Configure notifications for failures
Example Projects
Check out these example repositories:
Troubleshooting
Common issues and solutions:
-
Authentication Failures:
- Check credentials configuration
- Verify environment variables
-
Timeout Issues:
- Increase build timeout
- Optimize analysis scope
-
Workspace Problems:
- Clean workspace
- Check file permissions