gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:20 25 4
gpt4 key购买 nike

由于我是 Jenkins 的新手,即使在互联网上搜索了很长时间后,我似乎也无法找到适合我情况的正确解决方案。我在 tfs 中有两个存储库位置。 location1 具有在 linux env 上执行构建所需的 jenkinsfile 和其他文件,location2 具有相同的源文件,但 jenkins 文件和 bat 文件将需要在 windows env 中进行构建。

现在需要删除这个包含 windows 文件的存储库位置 2,并且现在需要将那里的 windows 功能添加到另一个存储库位置 1。因此,从本质上讲,该存储库需要具有可以在 linux 和 windows 上运行的 jenkinsfile。我不知道该怎么做。我读到我们可以做多配置工作。但是我该怎么做呢?

目前我在 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
}
}

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

}
}
}

我对这一切真的不是很有经验。如果有人能告诉我新的 jenkins 文件应该是什么样子就太好了?

编辑:我应该使用多配置项目还是自由式项目也可以并行构建运行?

最佳答案

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

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

节点步骤选择一个已配置正确标签的节点。

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

流水线构建不是自由式工作。多分支管道是关于构建存储库的多个分支 - 而不是关于构建所需的配置。

关于linux - 如何配置 jenkins 在同一个 jenkins 文件中构建多个节点(一个用于 linux,一个用于 windows)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com