简体   繁体   English

如何在同一jenkins文件中配置jenkins以在多个节点(一个用于linux,一个用于Windows)上构建?

[英]How to configure jenkins to build on multiple nodes (one for linux and one for windows) in the same jenkins file?

Since I am new to Jenkins I dont seem to be able to find a right solution that matches my situation even after searching in internet for a long time. 由于我是Jenkins的新手,因此即使在Internet上搜索了很长时间之后,我似乎也无法找到适合我情况的正确解决方案。 I have two repository locations in the tfs. 我在tfs中有两个存储库位置。 location1 has the jenkinsfile and other files needed to perform the build on linux env and the location2 has the same source files but jenkins file and bat files that will be needed to make a build in the windows env. location1具有在Linux env上执行构建所需的jenkinsfile和其他文件,而location2具有在Windows env中进行构建所需的相同源文件,但jenkins文件和bat文件。

Now this repository location2 with the windows files needs to be deleted and the windows functionality that was there, needs to be added now with the other repository location1. 现在,需要删除带有Windows文件的此存储库location2,并需要与其他存储库location1现在一起添加其中的Windows功能。 So inherently that repository needs to have the jenkinsfile that can work on linux and windows. 因此,从本质上讲,存储库需要具有可以在linux和Windows上运行的jenkinsfile。 I am not sure how to go about this. 我不确定该怎么做。 I read that we can do multiconfiguration jobs. 我读到我们可以做多配置工作。 But how do i do this? 但是我该怎么做呢?

currently the jenkinsfile i have for the Linux one is as below: 目前,我为Linux使用的jenkinsfile如下:

node('CentOs_Build_server)
{ 
stage('checkout')
    {
        checkout scm
    }

    stage('clean workspace')
    {
        sh '''
        git clean -fdx
        '''
    }

    stage('dependencies')
    {
                }

    stage('build')
    {
                }


    stage('archive artifacts')
    {
        archiveArtifacts 'build/*.rpm'
    }

        catch (err) {

    currentBuild.result = "FAILURE"

    echo "project build error: ${err}"

    throw err
}
}

and the jenkins file for the windows is as below: Windows的jenkins文件如下:

 node master

ws('D:\\Jenkins_Workspace\\OpcUaFramework_Latest')
{currentBuild.result = "SUCCESS"

try {
    stage('checkout')
    {
        checkout scm
    }

    stage('clean workspace')
    {
        bat '''
        git clean -fdx
        '''
    }

    stage('build')
    {
        bat '''
            " INSTALL.vcxproj /p:Configuration=Debug 
            rem MSBuild         }




    stage('archive artifacts')
    {
        archiveArtifacts '**/*.msi, **/*.zip'
    }



catch (err) 

{
    currentBuild.result = "FAILURE"
    echo "project build error: ${err}"
    throw err

}
}
}

I am really not that experienced with all this. 我真的没有那么多经验。 It would be really great idf someone can tell how the new jenkins file should look like ? 有人可以告诉我新的jenkins文件应该是什么样子,这真是很棒的idf?

edit : Should i use multiconfiguration project or is freestyle project is also possible for parallel builds to run? 编辑:我应该使用多配置项目还是自由样式项目也可以运行并行构建?

Here is a simple example that will run two builds in parallel on two different nodes using the same jenkinsfile: 这是一个简单的示例,它将使用相同的jenkinsfile在两个不同的节点上并行运行两个构建:

parallel (
    "Linux": {
        node('Linux')
        {
            # build steps
        }
    },
    "Windows": {
        node('Windows') 
        { 
            # build steps
        }
    }
)

The node step selects a node that has been configured with the right label. 节点步骤选择已配置了正确标签的节点。

This can be set in the node configuration screen for each node. 可以在每个节点的节点配置屏幕中进行设置。

Pipeline builds are not freestyle jobs. 管道构建不是自由式作业。 Multi-branch pipelines are about building many branches of a repository - not about the required configurations of building. 多分支管道与构建存储库的许多分支有关,而与构建所需的配置无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM