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

时间:2017-06-20 12:38:28

标签: linux windows jenkins

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. I have two repository locations in the 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.

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. So inherently that repository needs to have the jenkinsfile that can work on linux and windows. 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:

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:

 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 ?

edit : Should i use multiconfiguration project or is freestyle project is also possible for parallel builds to run?

1 个答案:

答案 0 :(得分:2)

这是一个简单的例子,它将使用相同的jenkinsfile在两个不同的节点上并行运行两个构建:

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

节点步骤选择已使用正确标签配置的节点。

可以在每个节点的节点配置屏幕中进行设置。

管道构建不是自由式作业。 多分支管道是关于构建存储库的许多分支 - 而不是构建所需的配置。

相关问题