简体   繁体   中英

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. 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?

Here is a simple example that will run two builds in parallel on two different nodes using the same 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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