哪个座席级别应用于输入?(Jenkins中的继承是什么样子的?)

mfuanj7w  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(104)
pipeline {
  agent none
  stages {
    stage('stage1') {
      agent any
      input {
        message "What is your first name?"
      }
      steps {
        echo "Test Stage1"
      }
    }
    stage('stage2'){
      steps{
        echo 'Test Stage2'
      }
    }
  }
}

1.在Jenkins的文献中:(https://www.jenkins.io/doc/book/pipeline/syntax/#agent)
代理无
当在管道块的顶层应用时,将不会为整个管道运行分配全局代理,并且每个阶段部分将需要包含其自己的代理部分。

  • stage2中,我没有为它定义代理。但是当我构建管道时,echo命令仍然正常执行。

1.在这个jenkinsfile中,agent none是顶级代理,agent anystage1的stage代理。
在jenkins的文档中输入:
在应用任何选项之后,在进入该阶段的代理程序块或评估该阶段的when条件之前,该阶段将暂停

  • 这是否意味着,输入是一个特殊的元素,所以只有顶层代理被应用于输入,而与我们在阶段级别中的代理无关,在哪个输入中定义?
  • 这种继承是Jenkins还是groovy脚本的特性?
kcwpcxri

kcwpcxri1#

echo命令只是打印到控制台,它不关心代理,
在服务器端执行的所有命令/groovy脚本(在jenkins示例上)
就像在你的例子中的命令echo "",但是如果你使用需要工作空间的东西,你会得到错误

ERROR: Attempted to execute a step that requires a node context while ‘agent none’ was specified. Be sure to specify your own ‘node { ... }’ blocks when using ‘agent none’.

仅在代理端执行特定命令,如sh块,它将通过jnlp协议(或ssh或其他任何内容,取决于您用于连接的内容)在代理上创建sh脚本,并将从jenkins远程执行此脚本
input -暂停管道执行以等待批准,这可能是自动的或手动的,默认情况下需要一些时间。与此同时,代理获取并锁定工作区和重量级Jenkins执行器。因此,在一个阶段内在代理之外创建输入总是很好的。
我们有2+案例
1.correct和输入将不会锁定代理

pipeline {
  agent none
  stages {
    stage('stage1') {
      steps {
        input "What is your first name?"
      }
    }
    stage('stage2') {
      agent any
      steps {
        input "What is your first name?"
      }
    }
  }
}

1.在“agent none”上执行错误输入,但阶段仍将锁定顶级代理(agent any)

pipeline {
  agent any
  stages {
    stage('stage1') {
      agent none
      steps {
        input "What is your first name?"
      }
    }
  }
}

1.correctuse nested stages,input will use top lvl agent none as nested stages agent already executed and removed

pipeline {
  agent none
  stages {
    stage('top stage for nested stages') {
      agent any
      stages {
        stage("nested stage1") {
          agent any
            steps {
              echo "hello"
            }
        }
        stage("nested stage2") {
          agent any
            steps {
              echo "hello"
            }
        }
      }
    }
    stage("top stage with input") {
      steps {
        input "What is your first name?"
      }
    }
  }
}

相关问题