输入应用哪个代理级别? (詹金斯中的继承是什么样的?)

问题描述 投票:0回答:1
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. 在詹金斯的文档中:(https://www.jenkins.io/doc/book/pipeline/syntax/#agent

代理无

当应用于管道块的顶层时,不会为整个管道运行分配全局代理,并且每个阶段部分都需要包含自己的代理部分。

  • stage2
    中我还没有为其定义代理。但是当我构建管道时,echo命令仍然正常执行。
  1. 在此 jenkinsfile 中

    agent none
    是顶级代理,
    agent any
    stage1
    的舞台代理。

    在jenkins的文档中进行输入:

应用任何选项后,进入该阶段的代理块或评估该阶段的条件之前,该阶段将暂停

  • 这是否意味着,输入是一个特殊元素,因此只有顶级代理才应用于输入,而与阶段级别中的哪个代理、定义的输入无关?
  • 这种继承是 Jenkins 或 Groovy 脚本的功能吗?
jenkins inheritance agent
1个回答
0
投票

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 远程执行此脚本

输入 - 暂停管道执行以等待批准,这可以是自动的或手动的,默认情况下需要一些时间。同时,代理获取并锁定工作空间和重量级 Jenkins 执行器。因此,在阶段内的代理之外创建输入总是好的。

© www.soinside.com 2019 - 2024. All rights reserved.