詹金斯管道步骤发生在主节点而不是从节点上 [英] Jenkins pipeline step happens on master instead of slave

查看:207
本文介绍了詹金斯管道步骤发生在主节点而不是从节点上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始使用Jenkins Pipeline.我的管道有一个简单的步骤,应该在其他代理上运行-例如限制在何处可以运行该项目"选项.

I am getting started with Jenkins Pipeline. My pipeline has one simple step that is supposed to run on a different agent - like the "Restrict where this project can be run" option.

我的问题是它在master上运行.

My problem is that it is running on master.

它们都是Windows计算机.

They are both Windows machines.

这是我的Jenkinsfile:

pipeline {
  agent {label 'myLabel'}
  stages {
    stage('Stage 1') {
      steps {
        echo pwd()
        writeFile(file: 'test.txt', text: 'Hello, World!')
      }
    }
  }
}

pwd()打印C:\Jenkins\workspace\<pipeline-name>_<branch-name>-Q762JIVOIJUFQ7LFSVKZOY5LVEW5D3TLHZX3UDJU5FWYJSNVGV4Q.

此文件夹位于主文件夹上. test.txt文件的存在确认了这一点.

This folder is on master. This is confirmed by the presence of the test.txt file.

我希望在从属代理上创建test.txt.

I expected test.txt to be created on the slave agent.

我可以确认管道找到代理,因为日志包含:

I can confirm that the pipeline finds the agent because the logs contain:

[Pipeline] node
Running on MyAgent in C:\Jenkins\workspace\<pipeline-name>_<branch-name>-Q762JIVOIJUFQ7LFSVKZOY5LVEW5D3TLHZX3UDJU5FWYJSNVGV4Q

但是,该文件夹在MyAgent上不存在,这似乎与问题有关.

But this folder does not exist on MyAgent, which seems related to the problem.

此问题类似于 Jenkins管道不遵守代理规范 ,只是我没有使用build指令,所以我认为答案不适用.

This question is similar to Jenkins pipeline not honoring agent specification , except that I'm not using the build instruction so I don't think the answer applies.

pipeline {
  agent any
  stages {
    stage('Stage 1') {
      steps {
        echo "${env.NODE_NAME}"
      }
    }
    stage('Stage 2') {
      agent {label 'MyLabel'}
      steps {
          echo "${env.NODE_NAME}"
      }
    }
  }
}

这将打印预期的输出-masterMyAgent.如果正确,那么为什么工作区位于master上的其他文件夹中,而不是在MyAgent上?

This prints the expected output - master and MyAgent. If this is correct, then why is the workspace located in a different folder on master instead of being on MyAgent?

推荐答案

我遇到了类似的问题,并且以下管道代码对我有用(即,该文件是在Windows从属设备而不是Windows主设备上创建的),

I faced similar issue and the following pipeline code worked for me (i.e. the file got created on the Windows slave instead of Windows master),

pipeline {
    agent none
    stages {
        stage("Stage 1") {
            steps {
                node('myLabel'){
                    script {
                        writeFile(file: 'test.txt', text: 'Hello World!', encoding: 'UTF-8')
                    }
                    // This should print the file content on slave (Hello World!)
                    bat "type test.txt"
                }
            }
        }
    }
}

这篇关于詹金斯管道步骤发生在主节点而不是从节点上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆