Skip to content
Novus Examples
jenkinsfile1.5 KB

Jenkinsfile, Declarative Pipeline

A declarative Jenkinsfile with a docker agent, options, environment and parameters blocks, a parallel test stage gated by a when expression, and post conditions. The dialect most Jenkins linters target.

Preview — first 50 linesjenkinsfile
pipeline {
    agent {
        docker {
            image 'registry.example.invalid/ci/node:20'
            args '-u 1000:1000'
        }
    }

    options {
        timeout(time: 30, unit: 'MINUTES')
        buildDiscarder(logRotator(numToKeepStr: '20'))
        disableConcurrentBuilds()
    }

    environment {
        BUILD_DIR = 'build'
        REGISTRY  = 'registry.example.invalid'
    }

    parameters {
        choice(name: 'ENVIRONMENT', choices: ['staging', 'production'], description: 'Target')
        booleanParam(name: 'RUN_INTEGRATION', defaultValue: false, description: 'Slow suite')
    }

    stages {
        stage('Install') {
            steps {
                sh 'npm ci'
            }
        }

        stage('Build') {
            steps {
                sh "npm run build -- --out ${env.BUILD_DIR}"
            }
        }

        stage('Test') {
            parallel {
                stage('Unit') {
                    steps {
                        sh 'npm run test:unit'
                    }
                }
                stage('Integration') {
                    when {
                        expression { return params.RUN_INTEGRATION }
                    }
                    steps {
                        sh 'npm run test:integration'
66 lines total — download for the full file.

Specifications

System
Jenkins
Syntax
declarative
Stages
3
Parallel Branches
2
Parameters
2
Post Conditions
2
Agent
docker

Testing contract

Expected to pass
Scenario
Parse a declarative Jenkinsfile and enumerate its stage tree and post conditions
Expected result
Three top-level stages resolve, the Test stage contains two parallel branches, and both post conditions (always, failure) are found

What is a .jenkinsfile file?

A Jenkinsfile defines a Jenkins pipeline as code. Declarative pipelines wrap a `pipeline` block containing agent, environment, options, stages, and post sections, while scripted pipelines are plain Groovy using `node` and `stage` steps; both are Groovy source, so the declarative form is validated against a schema before execution. It normally lives at the repository root with no file extension.

How to use this file

Use an example Jenkinsfile to test pipeline linters, Groovy parsers, and CI migration tooling, checking stage and parallel-branch extraction, environment-variable scoping, and that declarative-schema violations are reported with the offending block.

How to use this file for testing

“Jenkinsfile, Declarative Pipeline” is a deterministic Novus Examples fixture for Config testing, Config parsing, Editor testing. TOML, INI, YAML, .env, and dotfile configuration samples with nested sections and typed values — for testing config parsers, loaders, and environment tooling.

Documented properties for this file: JENKINSFILE · 1,523 bytes. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such — expect parsers to fail loudly rather than silently accept them.

Pipeline and infrastructure fixtures are inert configuration: steps reference fictional images and scripts, and nothing here executes. Run your linter, schema validator, migrator, or policy engine against them, and expect the deprecated-syntax and intentionally invalid variants to be rejected.

Point your config loader at the file and assert it reads the documented sections and typed values, including any deliberately-tricky nesting or comments.

Generated by generation/pipelines.py. Free for any use, no attribution required — license.