16

I am trying to run a Jenkins pipeline and I just keep getting the error:

Jenkins doesn't have label 'linux'

Any idea why this is happening? Is it a plugin I am missing?

pipeline {
    agent{
        label 'linux'
    }
    stages {
        stage('Checkout Code') {
            steps {
                checkout scm
            }
        }
        stage('Build Docker Container') {
            steps {
                script {
                    sh "ls -ltr"
                    env.HARBORHOST ="harbour.com"
                    env.REGISTRY = "securewbs"
                    env.IMAGE = "${env.HARBORHOST}/${env.REGISTRY}/securewbs:${env.BUILD_NUMBER}"
                    wbs = docker.build("${env.IMAGE}")
                }
            }
        }
Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
CPdev
  • 375
  • 2
  • 5
  • 20

4 Answers4

20

Go to Manage Jenkins->Manage Nodes. You can chose one of these nodes as your agent. Take the string from the column "name". If the name of one of your nodes is for example "master" you can write:

pipeline {
    agent {
        label 'master'
    }
    ...
}
Michael Käfer
  • 1,597
  • 2
  • 19
  • 37
  • 1
    The accepted answer did not work for me so I posted a new one. – Michael Käfer Apr 18 '19 at 16:10
  • 4
    On newer versions of jenkins it can be done by: _Manage Jenkins >> Manage Nodes and Cloud >> Click Node (on which you want to add a label) >> Configure >> Add label_. Labels are space separated if you want to add more than 1. – Anil Bhaskar Sep 04 '22 at 02:27
5

Look at the configuration section of your Jenkins instance (https://your-jenkins/configure). There is a section called Lockable Resources Manager, and your 'linux' label should be listed here.
The label is a selection field.

Mikki
  • 180
  • 2
  • Solved thanks - needed to add a 'linux' label to the node – CPdev Oct 04 '18 at 12:01
  • 4
    How does one add this label? @calumprice – George Udosen Sep 10 '19 at 16:22
  • @GeorgeUdosen There should be a field called "Label" in https://your-jenkins/configure Make sure that the label field of node block in your pipeline definition has the same value. – dimisjim Mar 06 '20 at 15:18
  • >needed to add a 'linux' label to the node @CalumPrice // then the one from Michael Kafer should be the accepted answer. It also helped me to add a label to the node. – bebyx Sep 28 '20 at 11:30
0

you need to add new variable or name or like a constant (i don't no exact name)

step 1. click on this link: http://localhost:8080/manage/configureTools/
step 2. add tool whatever you want like: node, maven, jdk , etc.
step 3. if it's not visible then first you need to install plugin according to your requirement.
step 4. try again step 2 and use you created "Name" in jenkins file.

enter image description here

Sandeep Pareek
  • 1,636
  • 19
  • 21
-3

if you can, avoid naming the agent, use pipeline { agent any ...

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30535826) – cerofrais Dec 08 '21 at 20:44