Use this when pipeline definitions live in the repository.
Jenkinsfile
A Jenkinsfile is the pipeline definition stored in the project's repository, so the build process is versioned and reviewed alongside the code.
1. Jenkinsfile describes the pipeline.
2. Validate before commit.
3. Keep logic in shared libraries.
4. Avoid credentials in the file.
5. Review changes.
Jenkinsfile → validation → pipeline
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Logic in the Jenkins UI instead of the Jenkinsfile.
- Secrets echoed in
shsteps.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- The Jenkinsfile lives in the project repository.
- Pipeline changes are reviewed like code.
- Multibranch pipelines build each branch.
- Jenkinsfile in repo root — location
curl -X POST -F 'jenkinsfile=<Jenkinsfile' https://<jenkins>/pipeline-model-converter/validate— validate declarative syntax- Shared library usage — reuse
ReferenceWhy it matters1 section · depth on demand
What it is
A Jenkinsfile defines the pipeline as code in the repository (declarative or scripted syntax).
ReferenceHow it works1 section · depth on demand
In depth
pipeline {
agent { label 'linux' }
options { timeout(time: 30, unit: 'MINUTES'); disableConcurrentBuilds() }
stages {
stage('Lint') { steps { sh 'yamllint . && ansible-lint' } }
stage('Test') { steps { sh 'pytest -q' } }
stage('Deploy') {
when { branch 'main' }
steps { input 'Deploy to production?'; sh './deploy.sh' }
}
}
post { failure { echo 'notify team' } }
}
Validate syntax before committing with the declarative linter (jenkins-cli declarative-linter < Jenkinsfile), and keep complex logic in scripts the Jenkinsfile calls, so it can be tested outside Jenkins.
ReferenceImportant terms & boundaries2 sections · depth on demand
Example
pipeline {
agent { label 'linux' }
stages {
stage('Lint') { steps { sh 'ansible-lint' } }
stage('Deploy') { when { branch 'main' } steps { sh 'ansible-playbook site.yml' } }
}
}
Mechanics
Its durable intent is versioned Jenkinsfile/job configuration, credentials references and agent/tool constraints; the stable identity contract is controller, job/folder, build number, stage/step, agent and artifact IDs. The operating invariants are that Jenkinsfile revision is known, credentials stay scoped, agent/tool requirements are reproducible, stage status is not confused with target-evidence of the actual state, and artifacts are traceable to one build. The linked authority for bounded mechanics is Jenkins User Handbook; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Jenkins > Jenkinsfile. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.jenkins.io/doc/ · confidence 94%