jenkins-pipeline

Pipeline editor unable to open Jenkinsfile in Jenkins BlueOcean

对着背影说爱祢 提交于 2019-12-22 13:31:09
问题 I am extremely new to BlueOcean and am getting the below error when trying to open the pipeline editor: There was an error loading the pipeline from the Jenkinsfile in this repository. Correct the error by editing the Jenkinsfile using the declarative syntax then commit it back to the repository. Cannot read property 'indexOf' of undefined Jenkinsfile : pipeline { agent any stages { stage('Build') { steps { echo 'Building..' } } stage('Test') { steps { echo 'Testing..' } } stage('Deploy') {

capture build number of downstream job in Jenkins code as pipeline

时光总嘲笑我的痴心妄想 提交于 2019-12-22 12:32:28
问题 Is there an environment variable that captures the downstream job's build number ? I am using build step in pipeline as code. 回答1: Not an environment variable, but an object property: downstreamBuild = build 'myDownstreamJob' downstreamBuildNumber = downstreamBuild.rawBuild.id Note that you will either need to disable the Groovy sandbox or get script approvals in order to use rawBuild . Also, you cannot use wait: false with your build step, since build() returns null when called with wait:

Jenkins Pipeline - SVN polling

China☆狼群 提交于 2019-12-22 11:37:10
问题 I have a Jenkins pipeline template which uses a Jenkins file in Subversion. The Jenkins file has the svn checkout method to check out the real application. (The svn url of real application is passed from jenkins env variables) I need to do the svn polling of the real application and trigger the job when there is a change in real application. When I use the polling option in jenkins template , it always do the polling of JenkinsFile in Subversion. Is there any way that I can poll the real

Mocking jenkins pipeline steps

被刻印的时光 ゝ 提交于 2019-12-22 10:51:42
问题 I have a class that i use in my jenkinsfile, simplified version of it here: class TestBuild { def build(jenkins) { jenkins.script { jenkins.sh(returnStdout: true, script: "echo build") } } } And i supply this as a jenkins parameter when using it in the jenkinsfile. What would be the best way to mock jenkins object here that has script and sh ? Thanks for your help 回答1: I had similar problems the other week, I came up with this: import org.jenkinsci.plugins.workflow.cps.CpsScript def

Jenkins Pipelines: Re-use workspace when loading an external Jenkins pipeline script

我只是一个虾纸丫 提交于 2019-12-22 09:59:50
问题 I have the following use case: Checkout/pull a certain Git revision, using written pipeline script (I need this because I retrieve the revision dynamically) From that revision, load a Jenkins-pipeline-file, located among the previously checked out files This file would rely on files from the same checked out revision (thus, from the same workspace) Problem: The loaded Jenkins-pipeline-file gets executed in a new workspace. But it is empty. I need that file to get executed in the same old

Jenkins Workflow: Parallelize step based on tool output

前提是你 提交于 2019-12-22 09:01:20
问题 I want to parallelize Jenkins stages based on the output of a test tool. However, I am encountering a problem because all parallel nodes are getting defined equally (in addition to the currently broken loops in the jenkins-workflow plugins). Trimmed down workflow script example: instances = ["one", "two", "three"] print "Testing instances: " + instances test_nodes = [:] for (int i = 0; i < instances.size(); i++) { instance_name = instances.get(i) println "Processing instance " + instance_name

Jenkins Pipeline - how to get logs from parallel builds

与世无争的帅哥 提交于 2019-12-22 06:51:15
问题 Is it possible, and if yes: how?, to get the log output for each parallel step separately? I.e.: def projectBranches = [:] for (int i = 0; i < projects.size(); i++) { def _i = i projectBranches[_i] = { someFunction(_i) } } parallel projectBranches Is it now possible to get the log for each of projectBranches[_i]? 回答1: You could get your nodes by use of Jenkins REST API: job/test/1/api/json?depth=2 Result should contain something like: {"_class":"org.jenkinsci.plugins.workflow.cps.nodes

How to know inside jenkinsfile / script that current build is a replay?

痴心易碎 提交于 2019-12-22 06:37:42
问题 As in subject - is there any way to verify if current build is effect of using 'Replay' button? 回答1: I found the following solution using the rawBuild instance from currentBuild . Since we can't get the class of the causes, we just verify its string value. def replayClassName = "org.jenkinsci.plugins.workflow.cps.replay.ReplayCause​" def isReplay = currentBuild.rawBuild.getCauses().any{ cause -> cause.toString().contains(replayClassName) } This solution works for Jenkins with Blue-Ocean.

Issue with Jenkins pipeline and java.nio.file.* methods

泪湿孤枕 提交于 2019-12-22 05:47:31
问题 I am trying to use methods from java.nio.file.* to perform some basic file operations in a Jenkins pipeline. Regardless of the node block in which the code exists, the code executes on the master node. In the pipeline, I have verified that the various node blocks are correct--they uniquely identify specific nodes. However, pathExists (and other code that moves, copies, or deletes files) always executes on the master node. Any ideas what's happening or how to fix it? import java.nio.file.*

How do I access files in a Shared Library?

我们两清 提交于 2019-12-22 04:58:09
问题 I have a Shared Library with a .groovy script that I call in a jenkinsfile like this: MySharedLibFunction{ .. some args} I also have a .ps1 file in my shared library I want to execute. But if I do powershell pwd from in my shared library function when I call that function from my jenkinsfile the current working directory is the jenkins working directory of my pipeline where the jenkinsfile is located (which is usually what you want). Is there a way to access files in the shared lib? I want to