jenkins-pipeline

How can I trigger another job from a jenkins pipeline (jenkinsfile) with GitHub Org Plugin?

五迷三道 提交于 2019-11-27 16:58:49
How can I trigger build of another job from inside the Jenkinsfile ? I assume that this job is another repository under the same github organization , one that already has its own Jenkins file. I also want to do this only if the branch name is master, as it doesn't make sense to trigger downstream builds of any local branches. Update: stage 'test-downstream' node { def job = build job: 'some-downtream-job-name' } Still, when executed I get an error No parameterized job named some-downtream-job-name found I am sure that this job exists in jenkins and is under the same organization folder as the

SparseCheckout in Jenkinsfile pipeline

佐手、 提交于 2019-11-27 16:43:24
问题 In a jenkinsfile, I have specified the folderName through SparseCheckoutPaths which I want to checkout. But I am getting a whole branch checkout instead. checkout([$class: 'GitSCM', branches: [[name: '*/branchName']], extensions: [[$class: 'SparseCheckoutPaths', path: 'FolderName']], userRemoteConfigs: [[credentialsId: 'someID', url: 'git@link.git']]]) 回答1: Here comes the answer to my own question. For a bit of background how does it work, there is flag/configuration for git client called

How do I get the SCM URL inside a Jenkins Pipeline or Multibranch Pipeline?

人盡茶涼 提交于 2019-11-27 16:11:51
问题 I am trying to get a prebuild merge to work inside a multibranch pipeline and I would like to avoid having to hardcode the git url in my pipeline script. It seems like scm step must store the url somehow, but I cannot figure out how to access it. 回答1: You are correct, the scm object does have the information you need. When using git as the source control in a Pipeline project (or Multibranch Pipeline project), the scm global variable will be an instance of GitSCM. That means that `scm

Jenkinsfile with two git repositories

泄露秘密 提交于 2019-11-27 15:47:38
问题 I'm using the Jenkins pipeline plugin with a Jenkinsfile. In one repository, called vms.git, I have the Jenkinsfile and an application it builds. I have another repository called deploy.git, which contains scripts I want to use to deploy the application in vms.git. At the moment my Jenkinsfile just looks like this node { stage 'build' checkout scm and I am defining the vms.git repo in the job configuration. So what I would like to do is check out both repositories, then use the Jenkinsfile in

Ignore failure in pipeline build step

走远了吗. 提交于 2019-11-27 15:46:16
问题 With jenkins build flow plugin this was possible: ignore(FAILURE){ build( "system-check-flow" ) } How to do this with Declarative Pipeline syntax? 回答1: To ignore a failed step in declarative pipeline you basically have two options: Use script step and try-catch block (similar to previous proposition by R_K but in declarative style) stage('someStage') { steps { script { try { build job: 'system-check-flow' } catch (err) { echo err } } echo currentBuild.result } } Use catchError stage(

Get absolute path to workspace directory in Jenkins Pipeline plugin

ⅰ亾dé卋堺 提交于 2019-11-27 15:26:11
I'm currently doing some evaluation on the Jenkins Pipeline plugin (formerly know as Workflow plugin). Reading the documentation I found out that I currently cannot retriev the workspace path using env.WORKSPACE : The following variables are currently unavailable inside a workflow script: NODE_LABELS WORKSPACE SCM-specific variables such as SVN_REVISION Is there any other way how to get the absolute path to the current workspace? I need this running some test which in turn gets some parameter (absolute path to some executable file). I already tried using new File("").absolutePath() inside a

How to get the changes since the last successful build in jenkins pipeline?

余生长醉 提交于 2019-11-27 14:48:48
问题 Anyone have a Jenkins Pipeline script that can stuff all the changes since the previous successful build in a variable? I'm using git and a multibranch pipeline job. 回答1: Well I managed to cobble something together. I'm pretty sure I you can iterate the arrays better but here's what I've got for now: node('Android') { passedBuilds = [] lastSuccessfulBuild(passedBuilds, currentBuild); def changeLog = getChangeLog(passedBuilds) echo "changeLog ${changeLog}" } def lastSuccessfulBuild

Active Choices Reactive Reference Parameter in jenkins pipeline

梦想的初衷 提交于 2019-11-27 14:10:00
问题 I'm using the Active Choices Reactive Reference Parameter plugin in a dsl job here the code parameters { activeChoiceParam('choice1') { description('select your choice') choiceType('RADIO') groovyScript { script("return['aaa','bbb']") fallbackScript('return ["error"]') } } activeChoiceReactiveParam('choice2') { description('select your choice') choiceType('RADIO') groovyScript { script("if(choice1.equals("aaa")){return ['a', 'b']} else {return ['aaaaaa','fffffff']}") fallbackScript('return [

Use a lightweight executor for a declarative pipeline stage (agent none)

杀马特。学长 韩版系。学妹 提交于 2019-11-27 13:55:07
问题 I'm using Jenkins Pipeline with the declarative syntax, currently with the following stages: Prepare Build (two parallel sets of steps) Test (also two parallel sets of steps) Ask if/where to deploy Deploy For steps 1, 2, 3, and 5 I need and agent (an executor) because they do actual work on the workspace. For step 4, I don't need one, and I would like to not block my available executors while waiting for user input. This seem to be referred to as either a "flyweight" or "lightweight" executor

How to set github commit status with Jenkinsfile NOT using a pull request builder

淺唱寂寞╮ 提交于 2019-11-27 12:58:23
问题 We have Jenkins 2 set to build every push to github, and we do not use the Pull Request builder (although commits that are part of a pull request obviously will get built, as well). The GitHub Integration Plugin says that it only works with the pull request builder, so this won't work for us. I've also tried the github-notify plugin, but it seems not to work for our case (possibly because the repo is private and/or owned as part of an Organizaiton, rather than an individual user). I have