Running Your First Pipeline

Create a Pipeline job, paste a Jenkinsfile, and click Build Now to watch the stages run.

Let's run a complete pipeline end to end.

Steps

  1. On the dashboard click New Item.
  2. Name it, choose Pipeline, and click OK.
  3. Scroll to the Pipeline section. For a quick test choose Pipeline script and paste the code below. For real projects choose Pipeline script from SCM to load a Jenkinsfile from Git.
  4. Click Save, then Build Now.

Watch it run

The Stage View appears, showing each stage as a column that turns green as it passes. Click any stage to see its logs.

Example

Example · bash
pipeline {
    agent any
    stages {
        stage('Hello') {
            steps {
                echo 'Hello, Jenkins Pipeline!'
            }
        }
        stage('Environment') {
            steps {
                sh 'echo "Running on: $(uname -a)"'
                sh 'date'
            }
        }
        stage('Done') {
            steps {
                echo 'Pipeline complete.'
            }
        }
    }
}

When to use it

  • A new Jenkins user creates their first Pipeline job by pasting a Jenkinsfile into the pipeline script text box in the UI.
  • A team member verifies that their new Jenkins installation works end-to-end by running a hello-world pipeline.
  • A developer tests a pipeline change quickly by using the Replay feature to edit and re-run the last build's Jenkinsfile.

More examples

Hello World pipeline

A two-step hello-world pipeline that prints the build number and hostname of the agent.

Example · groovy
pipeline {
  agent any
  stages {
    stage('Hello') {
      steps {
        echo "Hello from Jenkins build #${BUILD_NUMBER}"
        sh  'echo Running on: $(hostname)'
      }
    }
  }
}

Three-stage starter pipeline

A three-stage template that maps directly to Jenkins' Blue Ocean pipeline visualisation for beginners.

Example · groovy
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { sh 'echo Building...' }
    }
    stage('Test') {
      steps { sh 'echo Testing...' }
    }
    stage('Deploy') {
      steps { sh 'echo Deploying...' }
    }
  }
}

First real pipeline with SCM checkout

A first realistic pipeline that checks out the repo, installs dependencies cleanly, builds, and tests.

Example · groovy
pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps { checkout scm }
    }
    stage('Build') {
      steps { sh 'npm ci && npm run build' }
    }
    stage('Test') {
      steps { sh 'npm test -- --ci' }
    }
  }
}

Discussion

  • Be the first to comment on this lesson.