How to set up a Jenkins pipeline?
· Category: DevOps & CI/CD
Short answer
A Jenkins pipeline is set up by creating a new pipeline job and pointing it to a source control repository containing a Jenkinsfile.
Steps
- Click New Item and select Pipeline.
- Configure the repository URL and credentials.
- Set the script path to
Jenkinsfile. - Save and run the pipeline.
Example
pipeline {
agent any
environment {
NODE_ENV = 'production'
}
stages {
stage('Build') {
steps {
sh 'npm ci'
sh 'npm run build'
}
}
}
}
Tips
- Use Multibranch Pipelines for automatic branch scanning.
- Set webhook triggers for fast feedback.
- Archive artifacts with
archiveArtifacts.
Common issues
- Repository credentials must be configured correctly.
- The Jenkinsfile path is case-sensitive.
- Webhooks may fail if Jenkins is behind a firewall.