5

我正在尝试设置 jenkins-workflow 来进行我们的集成测试。我们的集成测试是这样工作的:

LibraryA有人在 git 的功能分支中进行了更改。我们希望 jenkins 对功能分支中的代码运行单元测试,然后我们希望将此功能分支中的代码安装到client1client2(它们是 的用户LibraryA)并运行他们的测试。

除了正确提交LibraryA. 相反,我的设置只是从LibraryA.

我们有很多功能分支,因此在工作流设置中对特定分支进行硬编码并不合适。似乎应该有某种方法来获取触发工作流作业的提交的哈希(即使使用 SCM 轮询)。

我的设置如下所示:

currentBuild.setDisplayName("#" + env.BUILD_NUMBER)

node {
  git credentialsId: '033df7f1-7752-46bd-903d-8a70e613eed0', url: 'git@github.com:mycompany/myrepo.git'
  sh '''
echo `git rev-parse HEAD` > libraryA_version.txt
sudo docker run --rm=true -e LANG=en_US.UTF-8 -a stdout -i -t mycompany/libraryA run_tests
'''
  archive 'libraryA_version.txt'
}

def integration_jobs = [:]

integration_jobs[0]={
  node{
    ws {
      unarchive mapping: ['libraryA_version.txt':'.']
      sh 'sudo docker run -t --rm mycompany/client1:v1 bash run_tests.sh "`cat libraryA_version.txt`"'
    }
  }
}

integration_jobs[1] = {
  node{
    ws {
      unarchive mapping: ['libraryA_version.txt' : '.']
      sh 'sudo docker run -t --rm mycompany/client2 run_tests.sh "`cat libraryA_version.txt`" '
    }
  }
}

parallel integration_jobs

所以,我目前的问题是如何设置 git repo/polling 以获得正确的提交以在第一个测试中运行,这将libraryA_version.txt在后续测试中使用?

或者,我应该以完全不同的方式进行此过程吗?

4

2 回答 2

4

正如@maybeg 暗示的那样,您最有可能寻找的是一个多分支项目,可通过安装Pipeline: Multibranch 获得。这使您可以在构建Jenkinsfile中简单地调用checkout scm一次或多次的脚本中定义脚本,从而避免需要libraryA_version.txt.

与此同时,我想知道您的项目设置。您的git步骤是使用默认值branch: 'master',这意味着它应该只在master分支上轮询开始,并且只检查这个分支。Git 插件相当复杂,所以也许这被某种方式破坏了。在等待适当的多分支支持之前,您始终可以使用配置为使用通配符分支规范的checkout步骤GitSCM,在这种情况下,将选择以前未构建的任意分支头进行结帐,以及您的git-rev-parse技巧(我猜您独立地重新发现了JENKINS的解决方法-26100 ) 应该按原样工作。

于 2015-07-21T14:48:31.113 回答
0

The feature you are looking for is Build-Per-Branch and in my view it should be implemented accordingly through fit-for-purpose plugins.

  • Branching is done in git.

  • Jenkins must copy the build or build pipeline job to fit the branch and being able to build and test the branch.

  • After reintegration git must inform Jenkins and Jenkins must shut down the jobs.

I found this plugin:

https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin

And this plugin/tutorial:

http://entagen.github.io/jenkins-build-per-branch/

The implementation is strongly dependent on your scenario so i can't be more specific. I just say the challenges are:

  • Building Jenkins jobs that can run concurrently and independently.

  • Working with templates for Jenkins jobs.

  • Handling events between Jenkins and git.

In your case:

  • Build the whole process as a delivery pipeline from front to end.

  • If someone branches a step and implements a feature then copy the whole pipeline and run the whole pipeline.

  • Get this working then improve.

于 2015-07-11T11:48:37.790 回答