jenkins-pipeline

Jenkins Multibranch pipeline: What is the branch name variable?

折月煮酒 提交于 2019-11-29 00:53:27
I'm new to the Jenkins Pipeline plugin, and especially new to the multibranch pipeline plugin. In a standard build I have access to the $GIT_BRANCH variable to know which branch is being built. However that variable isn't set in the multibranch pipeline. I have tried env.GIT_BRANCH too, and I tried to pass $GIT_BRANCH as a parameter to the build. Nothing seems to work. I assumed that since the build knows about the branch being built (I can see the branch name at the top of the console output, that there is something that I can use, I just can't find any reference to it. Here is an example of

Use ssh credentials in jenkins pipeline with ssh, scp or sftp

三世轮回 提交于 2019-11-28 23:00:20
问题 I want to use scp/ssh to upload some files to a server. I discover that I need to use certificate-based authentication, but the question is how? Really what I want to do is to use the same sort of credentials I use with git - passworded ssh cert stored in Jenkins. However, I can't work out how to - the snippet generator has no obvious option for that. What do others do? Is there an undocumented feature that would do this? 回答1: If you install the SSH Agent plugin you can use the ssh-agent

How to lock multiple stages of declarative Jenkins pipeline?

守給你的承諾、 提交于 2019-11-28 22:52:32
问题 I want to run multiple stages inside a lock within a declarative Jenkins pipeline: pipeline { agent any stages { lock(resource: 'myResource') { stage('Stage 1') { steps { echo "my first step" } } stage('Stage 2') { steps { echo "my second step" } } } } } I get the following error: Started by user anonymous org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 10: Expected a stage @ line 10, column 9. lock(resource: 'myResource') { ^ WorkflowScript: 10

Job DSL to create “Pipeline” type job

狂风中的少年 提交于 2019-11-28 22:28:47
问题 I have installed Pipeline Plugin which used to be called as Workflow Plugin earlier. https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin I want to know how can i use Job Dsl to create and configure a job which is of type Pipeline 回答1: You should use pipelineJob: pipelineJob('job-name') { definition { cps { script('logic-here') sandbox() } } } You can define the logic by inlining it: pipelineJob('job-name') { definition { cps { script(''' pipeline { agent any stages { stage('Stage 1')

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

非 Y 不嫁゛ 提交于 2019-11-28 21:20:42
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 for the classic, scripted syntax, but I cannot find any information on how to achieve this with the

How to create methods in Jenkins Declarative pipeline?

前提是你 提交于 2019-11-28 20:54:15
问题 In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how? 回答1: Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script: pipeline { agent any stages { stage('Test') { steps { whateverFunction() } } } } void whateverFunction() { sh 'ls /' } 回答2: You can create a groovy function like this and

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

时光怂恿深爱的人放手 提交于 2019-11-28 20:30:21
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 tried letting it infer settings as well as manually specifying credentialsId , account , repo , and of

Does Jenkins Pipeline Plug-in support Docker Compose?

﹥>﹥吖頭↗ 提交于 2019-11-28 19:07:57
I'm looking for a way to run Docker-enabled build consisting of multiple containers in Jenkins 2.0. Are there any plans for native support of Docker Compose in Pipeline , or through CloudBees docker plugins for pipeline. Or can/must this be addressed by explicit calls sh docker-compose... ? Maybe even use them inside try... finally to further control services lifecycle. EDIT: The first answer was to suggest a way to build docker containers in jenkins. This is not what is needed here. I (EngineerDollery) want to bring up my target platform in jenkins using compose so that I can deploy my app to

How to send Slack notification after Jenkins pipeline build failed?

旧时模样 提交于 2019-11-28 18:56:01
问题 I have a pipeline groovy script in Jenkins v2.19. Also I have a "Slack Notification Plugin" v2.0.1 and "Groovy Postbuild Plugin". I have successfully send a message "build started" and "build finished" (if it had). When some build step failed – how I can send a message "Build failed" to the Slack channel? 回答1: You could do something like this and use a try catch block. Here is some example Code: node { try { notifyBuild('STARTED') stage('Prepare code') { echo 'do checkout stuff' } stage(

How to trigger a Jenkins 2.0 Pipeline job from a GitHub pull request

余生颓废 提交于 2019-11-28 16:47:31
问题 It looks like the GitHubPullRequestBuilder is not compatible with Jenkins v2.0 pipeline jobs. How do you configure a pipeline job to be triggered from a GitHub pull request event? The documentation on this topic is sparse and I cannot find any examples of this. Or is it better to create a web-hook in GitHub to trigger the pipeline job on the PR event? 回答1: The most straightforward way to use Pipeline with GitHub pull requests is to put the script into your repository under the name