jenkins-pipeline

How to list all `env` properties within jenkins pipeline job?

孤者浪人 提交于 2019-11-27 06:46:52
Given a jenkins 2.1 build pipeline, jenkins injects a env variable into the node{} . For example, BRANCH_NAME can be accessed with node { echo ${env.BRANCH_NAME} ... I want to echo all env properties within the jenkins pipeline. I'm looking for code like node { for(e in env){ echo e + " is " + ${e} } ... which would echo something like BRANCH_NAME is myBranch2 CHANGE_ID is 44 ... Another, more concise way: node { echo sh(returnStdout: true, script: 'env') // ... } cf. https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script According to Jenkins documentation

Jenkinsfile Declarative Pipeline defining dynamic env vars

回眸只為那壹抹淺笑 提交于 2019-11-27 06:44:19
I'm new to Jenkins pipeline; I'm defining a declarative syntax pipeline and I don't know if I can solve my problem, because I didn't find a solution. In this example, I need to pass a variable to ansible plugin (in old version I use an ENV_VAR or injecting it from file with inject plugin) that variable comes from a script. This is my perfect scenario (but it doesn't work because environment{}): pipeline { agent { node { label 'jenkins-node'}} stages { stage('Deploy') { environment { ANSIBLE_CONFIG = '${WORKSPACE}/chimera-ci/ansible/ansible.cfg' VERSION = sh("python3.5 docker/get_version.py") }

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

◇◆丶佛笑我妖孽 提交于 2019-11-27 06:21:54
I am new to docker. I just tried to use docker in my local machine(Ubuntu 16.04) with Jenkins. I configured a new job with below pipeline script. node { stage('Build') { docker.image('maven:3.3.3').inside { sh 'mvn --version' } } } But it fails with below error. austingray The user jenkins needs to be added to the group docker : sudo usermod -a -G docker jenkins Then restart Jenkins. Edit If you arrive to this question of stack overflow because you receive this message from docker, but you don't use jenkins, most probably the error is the same: your unprivileged user does not belong to the

jenkins pipeline: agent vs node?

旧街凉风 提交于 2019-11-27 06:13:24
What is the difference between an agent and a node in a jenkins pipeline? I've found those definitions: node : Most work a Pipeline performs is done in the context of one or more declared node steps. agent : The agent directive specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent directive is placed. So both are used for executing pipeline steps. But when to use which one? Jon S The simple answer is, Agent is for declarative pipelines and node is for scripted pipelines. In declarative pipelines the agent directive is

Error “The input device is not a TTY”

大城市里の小女人 提交于 2019-11-27 05:57:55
I am running the following command from my Jenkinsfile . However, I get the error "The input device is not a TTY" . docker run -v $PWD:/foobar -it cloudfoundry/cflinuxfs2 /foobar/script.sh Is there a way to run the script from the Jenkinsfile without doing interactive mode? I basically have a file called script.sh that I would like to run inside the Docker container. Remove the -it from your cli to make it non interactive and remove the TTY. If you don't need either, e.g. running your command inside of a Jenkins or cron script, you should do this. Or you can change it to -i if you have input

How to manipulate the build result of a Jenkins pipeline job?

这一生的挚爱 提交于 2019-11-27 05:25:46
I'm having some trouble to manipulate the build result of a Jenkins pipeline. I've narrowed it down to the following issue: anyone know why the following Jenkins pipeline doesn't make the build result SUCCESS? Instead the build fails. print "Setting result to FAILURE" currentBuild.result = 'FAILURE' print "Setting result to SUCCESS" currentBuild.result = 'SUCCESS' Joost I guess this is by design, "result can only get worse" in setResult() : // result can only get worse if (result==null || r.isWorseThan(result)) { result = r; LOGGER.log(FINE, this + " in " + getRootDir() + ": result is set to "

Git inside docker inside Jenkins pipeline doesnt work

百般思念 提交于 2019-11-27 04:53:18
问题 I am trying to perform some git queries inside a docker container that runs as part of a Jenkins Pipeline. Out side the docker container the sshsgent is working fine and I can access my SCM no problem. Inside the container I am getting host key verification issues. Can anyone help with the mistake I have made? script { sshagent(['e9f7d09a-7b88-4bf7-814c-464f811d9519']) { sh(""" ssh -p 7999 git@bitbucket-eng-gpk1.com whoami """) } docker.withRegistry('https://dockerhub.banana.com', 'banana

jenkins notifying error occured in different steps by sending mail in Pipeline (former known as Workflow)

最后都变了- 提交于 2019-11-27 04:44:01
问题 I have a pipeline with multiple steps, for example: stage 'dev - compile' node('master') { //do something } stage 'test- compile' node('master') { //do something } stage 'prod- compile' node('master') { //do something } I want to send a email if something goes wrong in the job, how can I send an email no matter where the error got triggered, something like: try { /** all the code above **/ } catch(Exception e) { mail the error } 回答1: I think it is a better way to use the jenkins build in post

Jenkins pipeline sh fail with “cannot run program nohup” on windows

馋奶兔 提交于 2019-11-27 04:29:50
I have windows 10 and I want to execute the sh command in the Jenkinsfile from Jenkins pipeline using bash for Ubuntu for windows, but it doesn't work I have the following stage in my Jenkins pipeline : stage('sh how to') { steps { sh 'ls -l' } } The error message is : [C:\Program Files (x86)\Jenkins\workspace\pipelineascode] Running shell script Cannot run program "nohup" (in directory "C:\Program Files (x86)\Jenkins\workspace\pipelineascode"): CreateProcess error=2, Le fichier spécifié est introuvable I tried changing Jenkins parameter->shell executable with C:\Windows\System32\bash.exe but

How do I use Jenkins Pipeline properties step?

雨燕双飞 提交于 2019-11-27 04:26:24
问题 I am studying capabilities of Jenkins Pipeline:Multibranch. It is said that a recently introduced properties step might be useful there, but I can't catch how it works and what is its purpose. Its hint message doesn't seem to be very clear: Updates the properties of the job which runs this step. Mainly useful from multibranch workflows, so that Jenkinsfile itself can encode what would otherwise be static job configuration. So I created a new Pipeline with this as a script (pasted directly