共享库的 Jenkins 函数在错误的节点上执行

问题描述 投票:0回答:0

我有一个简单的共享库,想调用一个创建文件的函数。 我的管道脚本如下所示:

@Library('jenkins-shared-library')_

pipeline {
    agent {
        node {
             label 'node1'
        }
    }
 
    stages {
        stage('test') {
            
            steps {
                script {
                    def host = sh(script: 'hostname', returnStdout: true).trim()
                    echo "Hostname is: ${host}"
                    
                    def testlib = new TestLibrary(script:this)
                    testlib.createFile("/tmp/file1")
                }
            }
        }
    }
}

此管道作业由运行在内置主节点上的另一个作业触发。 “测试”阶段在“节点 1”上正确执行。

问题:创建的文件“/tmp/file1”是在 jenkins master 上创建的,而不是“node1”

jenkins-pipeline shared-libraries jenkins-shared-libraries
© www.soinside.com 2019 - 2024. All rights reserved.