jenkins-pipeline

Using credentials from Jenkins store in a jenkinsfile

别等时光非礼了梦想. 提交于 2019-11-29 17:15:48
问题 I made a multibranch pipeline project in Jenkins. I need to use two repositories and both need credentials. I created a Jenkinsfile in repository1: node ('label1'){ stage 'sanity check' sh 'echo sanity check' stage 'checkout other repository' checkout([ $class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[url: 'https://BRNTZN@bitbucket.org/BRNTZN/repository2.git'],[credentialsId:'23b2eed1-2863-49d5-bc7b-bcccb9ad914d']] ]) stage 'log results' sh 'echo result = OK' } When I

How to get the BUILD_USER in Jenkins when job triggered by timer?

孤街醉人 提交于 2019-11-29 16:30:21
问题 I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable BUILD_USER . But this variable do not get initialized when the job is triggered by a scheduler. How can we achieve this? I know we have a plugin called - EnvInject Plugin, and that can be used... But I just want to know how we can use this and achieve the solution... 回答1: This can be done using the Jenkins Build User Vars Plugin which

How to configure a Jenkins 2 Pipeline so that Jenkinsfile uses a predefined variable

孤者浪人 提交于 2019-11-29 16:20:40
I have several projects that use a Jenkinsfile which is practically the same. The only difference is the git project that it has to checkout. This forces me to have one Jenkinsfile per project although they could share the same one: node{ def mvnHome = tool 'M3' def artifactId def pomVersion stage('Commit Stage'){ echo 'Downloading from Git...' git branch: 'develop', credentialsId: 'xxx', url: 'https://bitbucket.org/xxx/yyy.git' echo 'Building project and generating Docker image...' sh "${mvnHome}/bin/mvn clean install docker:build -DskipTests" ... Is there a way to preconfigure the git

How to import a file of classes in a Jenkins Pipeline?

梦想的初衷 提交于 2019-11-29 15:52:10
I have a file that contains classes. Example : abstract class TestBase { String name abstract def fTest() def bobby(){ return "bobby" } } class Test extends TestBase { def fTest(){ return "hello" } } class Test2 extends TestBase { def fTest(){ return "allo" } def func(){ return "test :)" } } I want to import the file in my Jenkins pipeline script, so I can create an object of one of my class. For example : def vTest = new Test() echo vTest.fTest() def vTest2 = new Test2() echo vTest2.func() How can I import my file in my Jenkins Pipeline ? Thx. you can do like this: Classes.groovy class A{ def

Jenkins Build Periodically - Schedule

余生颓废 提交于 2019-11-29 14:06:11
I am looking to build periodically every 15 minutes. I have looked online and I am using this schedule: */15 * * * * Jenkins is telling me to spread load evenly by using H/15 * * * * rather than */15 * * * * Could someone tell me the difference between using H instead of * ? Avihoo Mamka Yes. From the Build Triggers → Build periodically → Schedule → inline help: To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast

Error: The parallel step can only be used as the only top-level step

≡放荡痞女 提交于 2019-11-29 13:56:45
问题 When I use this script it works as expected: stage("B") { parallel ( 'C' : { stage ("BC") { parallel ( 'E' : { stage("Many") { println "E1" println "E2" } }, 'F' : { println "F" } ) } }, 'D' : { println "D" } ) } But if enclosed in a pipeline block it fails with an Error "Invalid step 'stage' used - not allowed in this context - The stage step cannot be used in step blocks in Pipeline" pipeline { agent label:"debian" stages { stage("B") { parallel ( 'C' : { stage ("BC") { parallel ( 'E' : {

What does a ws() block do in Jenkins?

谁说我不能喝 提交于 2019-11-29 13:36:10
问题 I'm trying to convert few Jenkinsfile s from Scripted Pipeline to Declarative Pipeline. I have a block like this in a Jenkinsfile : ws("/path/to/dir") { // do stuff } I wonder what does it do exactly and what's the proper way to convert it to the Declarative Pipeline syntax. 回答1: ws allocates a new workspace. you would use this to ensure that nothing else interferes with the location on disk where you are running the enclosed steps. this is not as heavy-handed as the node step, since node

Github Webhook With Jenkins return 302 NotFound

筅森魡賤 提交于 2019-11-29 13:32:17
问题 I set up localhost jenkins, using ngrok to expose my jenkins to github. I didn't set up any credentials. When I test delivery from webhook, it shows 302 not found. Response: Content-Length: 0 Date: Mon, 16 Apr 2018 02:09:22 GMT Location: http://056b05cb.ngrok.io/github-webhook/ Server: Jetty(9.4.z-SNAPSHOT) X-Content-Type-Options: nosniff Request: Headers Request URL: http://056b05cb.ngrok.io/github-webhook Request method: POST content-type: application/json Expect: User-Agent: GitHub

Currying groovy CPS closure for parallel execution

瘦欲@ 提交于 2019-11-29 13:27:23
We do some dynamic creation of parallel steps in some of our jobs. Thanks to this thread I found how to dynamically create the map with parameters for use in the parallel step. However now I wanted to reuse parts of the code which is used to create those parallel steps. For this I feel that I would need to curry the closures. However currying seems not to work correctly. Referencing the loop variable (valueCopy) inside the closure does the right thing ( as mentioned here ) but currying does not do what I would expect. Am I doing something wrong, is this just not (yet) supported, are there any

Is there a way to automatically build tags using the Multibranch Pipeline Jenkins plugin?

北城余情 提交于 2019-11-29 12:26:01
问题 After creating a Multibranch Pipeline in Jenkins I can easily tell it to poll for changes or additions of any branches and it will automatically create jobs for and build those branches. I told the Multibranch job to also discover tags, so it automatically creates jobs for each tag, which is great. Is there a clean way for Jenkins to automatically build those tags as well, instead of me having to trigger them manually? As you can see below, the job for the tag is there, but I have to manually