jenkins-pipeline

Jenkins Git Environment variables not set in Pipeline

做~自己de王妃 提交于 2019-12-07 23:49:22
问题 I am trying to read some environment variables in Jenkins pipeline script that should be set by Git plugin, but it seems they are not set, because when I tried to use in script its value is empty string and also if I use sh 'printenv' I can see that they are not set. Probably I am missing something but I cannot find what. Any idea? 回答1: Per this page: http://JenkinsURL/pipeline-syntax/globals: SCM-specific variables such as GIT_COMMIT are not automatically defined as environment variables;

Template docker agent in jenkins Declarative pipeline

[亡魂溺海] 提交于 2019-12-07 18:04:49
问题 I have a Jenkinsfile for a declarative pipeline that uses docker agents. A number of the steps use a docker agent and it is a bit repetitive adding the same agent for these steps e.g. pipeline { agent any stages { stage('Stage 1') { steps { //Do something } } stage('Stage 2') { agent { docker { image 'jenkins/jenkins-slave:latest' reuseNode true registryUrl 'https://some.registry/' registryCredentialsId 'git' args '-v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -e HOME=${WORKSPACE}' } }

Jenkins pipeline error - “process apparently never started in …”

戏子无情 提交于 2019-12-07 15:55:27
Getting below strange error in Jenkins pipeline [Pipeline] withDockerContainer acp-ci-ubuntu-test does not seem to be running inside a container $ docker run -t -d -u 1002:1006 -u ubuntu --net=host -v /var/run/docker.sock:/var/run/docker.sock -v /home/ubuntu/.docker:/home/ubuntu/.docker -w /home/ubuntu/workspace/CD-acp-cassandra -v /home/ubuntu/workspace/CD-acp-cassandra:/home/ubuntu/workspace/CD-acp-cassandra:rw,z -v /home/ubuntu/workspace/CD-acp-cassandra@tmp:/home/ubuntu/workspace/CD-acp-cassandra@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ********

How to trigger parameterized build on successful build in Jenkins?

懵懂的女人 提交于 2019-12-07 15:54:05
问题 I have three pipeline projects, project-a, project-b and project-c. project-c takes a parameter. On successful completion of either project-a or project-b I want to trigger a build of project-c with a parameter. I can do this in project-a and project-b with this code in the pipeline: stage('trigger-project-c') { def job = build job: 'project-c', parameters: [[$class: 'StringParameterValue', name: 'MY_PARAM', value: 'somevalue']] } But this requires two executors. I want project-a or project-b

Is there a way to move the entire post {} build section in Jenkinsfile to the global pipeline library?

蹲街弑〆低调 提交于 2019-12-07 14:44:03
问题 I'm relatively new to Jenkins pipelines, but having implemented already a few, I've realised I need to start using jenkins shared library before I go mad. Have already figured out how to define some repetitive steps in the library and call them with less clutter from Jenkinsfile, but not sure if the same thing can be done for the entire post build section (thought I've read about to how to define the entire pipeline in the lib and similar), as this is pretty much static end of every single

Capturing shell script output from Jenkins Pipeline

大憨熊 提交于 2019-12-07 13:32:45
问题 I am trying to extract git branch and commit information in my Jenkinsfile as following: def commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() def branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() I am trying to print it afterwards like this: println("Branch: ${branch}, Commit: ${commit}") Instead of getting real values, I am left with this: Branch: org.jenkinsci.plugins.pipeline.modeldefinition.ClosureModelTranslator@545511bf, Commit: org

how to pass project parameter as branch name to build in Jenkins

拜拜、爱过 提交于 2019-12-07 13:27:02
问题 I am wondering is there any way we can pass the value of project parameter as the Git branch to build from. Below is what I am trying to do: Create a Jenkins pipeline project with a build parameter: Then I tried to using the project parameter to pass it on (Branches to build) However the branch_name variable is not resolved from the project parameter. I could do manually change branch name for every build, but it is far from ideal. Appreciate for any idea? 回答1: This issue has been reported

With Git feature branch workflow, when do you update the master branch?

拜拜、爱过 提交于 2019-12-07 13:20:15
问题 I'm fairly new to git and Jenkins. We want to use Jenkins and follow the feature-branch-workflow concept, which I believe is similar to the GitHub flow. I'm aware that the master branch should always be what's currently deployed in production, but then when should the master branch be updated? It seems like there are two choices: BEFORE deploying to production: A pull request gets approved and the successful merge with master triggers the build, deployment to a staging environment, QA testing

Jenkins pipeline email not sent on build failure

左心房为你撑大大i 提交于 2019-12-07 11:13:07
问题 I am using following step in my pipeline jenkins job: step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'my@xyz.com', sendToIndividuals: true]) But no email was sent when the build failed (i.e. error). Any pointers why? P.S. Emails can be sent from this server, I have tested that. 回答1: Use Declarative Pipelines using new syntax, for example: pipeline { agent any stages { stage('Test') { steps { sh 'echo "Fail!"; exit 1' } } } post { always { echo 'This will always run' }

Jenkins Script Pipeline sonar Integration

你说的曾经没有我的故事 提交于 2019-12-07 10:26:16
问题 i'd like to start a Sonar project analysis with Jenkins 2.x Groovy Script Build Pipeline. I have sonar configured in Maven so thats no big deal: withEnv(["JAVA_HOME=${javaHome}", "PATH + MAVEN=${mavenHome}/bin:${env.JAVA_HOME}/bin", "MAVEN_OPTS=${mavenOpts}"]) { sh 'mvn -B sonar:sonar' } But how can i get results from sonar ? Or even better how can i determine if a quality gate was achived so that i can stop the build-pipeline. The build breaker concept is obsolet since some versione of sonar