首页 > 解决方案 > jenkinsfile 在主代理上执行

问题描述


我开始使用 jenkinsfiles。
jenkins 文件包含一条回显消息(即 Hello world)
这是我的情况:我在带有 so windows(主代理)的 PC 上安装了 jenkins(版本 2.190.1)。我的奴隶代理是一台带有so linux的电脑。我把我的詹金斯文件放在我的 scm 中。我已成功配置管道以运行 jenkinsfile。这是成功完成的。
Jenkins 在 *master agent* 而不是 *slave agent*(我想要的)上进行存储库签出,并且 *option "Lightweight checkout"* 被选中。
我想要这种行为,因为我的管道必须在从代理上工作。而且我不希望我的存储库在主代理上。我在网上搜索了可能的解决方案,但没有结果。

你能给我一个关于如何直接在从代理上签出我的存储库的建议吗?

标签: jenkinsjenkins-pipeline

解决方案


可以这样做。从下面的示例中,只需替换agentLabelName为您的代理名称。

脚本流水线

node('agentLabelName') {
    stage('stageName') {
        echo "${env.WORKSPACE}"
        //checkout scm // If Jenkinsfile availabe with your SCM
        git url: 'https://github.com/samitkumarpatel/test0.git', branch: 'main'
    }
}

声明式管道

pipeline {
    agent {
        label 'agentLabelName'
    }
    stages {
        stage('stageName') {
            steps {
                echo "Hello World"
                echo "${env.WORKSPACE}"
                //checkout scm // If Jenkinsfile availabe with your SCM
                git url: 'https://github.com/samitkumarpatel/test0.git', branch: 'main'
            }
        }
    }
}


推荐阅读