jenkins-pipeline

How to checkout ssh remote in github organization Jenkins workflow and use ssh credentials in Jenkinsfile

我只是一个虾纸丫 提交于 2019-12-05 05:51:38
I have a Github Organisation item in jenkins. On the root of my repository, my Jenkinsfile looks something like this: node { def jenkinsCredsId = 'xxxxxxxx-yyyy-zzzz-aaaa-bbbbbbbbbbbb' stage 'Checkout' checkout scm // I also tried the following: // checkout scm: [$class: 'GitSCM', source: 'ssh://git@github.com:MY_ORGANISATION/jenkins-testing-temp.git', clean: true, credentialsId: jenkinsCredsId] stage 'Build' // generate some artefact (dist.zip) stage 'Release' sshagent([jenkinsCredsId]) { sh ''' git remote -v // show remotes ssh-add -l // show currently loaded ssh keys fingerprints git fetch

Execute a script from jenkins pipeline

爱⌒轻易说出口 提交于 2019-12-05 05:40:15
I have a jenkins pipeline that builds a java artifact, copies it to a directory and then attempts to execute a external script. I am using this syntax within the pipeline script to execute the external script dir('/opt/script-directory') { sh './run.sh' } The script is just a simple docker build script, but the build will fail with this exception: java.io.IOException: Failed to mkdirs: /opt/script-directory@tmp/durable-ae56483c The error is confusing because the script does not create any directories. It is just building a docker image and placing the freshly built java artifact in that image.

How to access git branch name from pipeline job?

独自空忆成欢 提交于 2019-12-05 05:24:10
I have a Jenkins Pipeline job which is configured to checkout a git repo and a specific local branch. How can i get the name of the local branch in my Jenkinsfile? I tried to load the git jenkins plugin env properties but had no luck. node { checkout scm echo "1 "+ env.GIT_LOCAL_BRANCH echo "2 "+ env.GIT_BRANCH } Both values are "null" I found that I can capture the return value from checkout scm and use that to get the branch name (and other values) def scmVars node('api-sample-build') { stage('Clone source code') { scmVars = checkout scm // scmVars contains the following values // GIT_BRANCH

How can I have a Jenkins pipeline build be triggered from a repository with no jenkinsfile?

老子叫甜甜 提交于 2019-12-05 05:03:24
I have a repository that does not contain a Jenkinsfile - and I have no way of influencing the repository itself. This means I can neither add nor alter any files to or in the repository (In this case, its the Qt repo ). What I want to do is create multiple Jenkinsfiles, that are each configuring and building the Qt library for a different target, or run different additional scripts. All these Jenkinsfiles will be collected in a different repository. Now, my problem is how to create a pipeline job, that gets triggered, as soon as there are changes in the Qt repository, but uses a Jenkinsfile

How do you handle global variables in a declarative pipeline?

淺唱寂寞╮ 提交于 2019-12-05 04:27:47
Previously asked a question about how to overwrite variables defined in an environment directive and it seems that's not possible. I want to set a variable in one stage and have it accessible to other stages. In a declarative pipeline it seems the only way to do this is in a script{} block. For example I need to set some vars after checkout. So at the end of the checkout stage I have a script{} block that sets those vars and they are accessible in other stages. This works, but it feels wrong. And for the sake of readability I'd much prefer to declare these variables at the top of the pipeline

Jenkins Pipeline Docker Agent Setup Dynamically

半世苍凉 提交于 2019-12-05 03:26:18
问题 In declarative pipelines we set up docker agent as below, pipeline { agent { docker { image dockerImage args dockerArgs registryUrl dockerRegistryUrl registryCredentialsId dockerRegistryCredentialsId label dockerLabel alwaysPull true } } .... but I want to do something like this, def dockerAgent = new Docker(dockerImage, dockerArgs,...) pipeline { agent { dockerAgent } } .... The intention is to generate Docker Agent with the properties using a shard-lib and inject the agent to the pipeline.

Error with changeSet in jenkins pipeline (Error:java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList)

£可爱£侵袭症+ 提交于 2019-12-05 03:09:25
I have this error: java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList when ChangeSet!=null but the strange is that the error ocurred when updating this plugin: Pipeline Shared Groovy Libraries, before this work good, i use jenkins v 2.21 and pipeline 2.4 and my code is the next: def changeLogSets = currentBuild.rawBuild.changeSets for (int i = 0; i < changeLogSets.size(); i++) { def entries = changeLogSets[i].items for (int j = 0; j < entries.length; j++) { def entry = entries[j] echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}" def

Jenkins Workflow Multibranch allow for specifying Jenkinsfile path

限于喜欢 提交于 2019-12-05 02:49:31
It seems like now you can only have a single Jenkinsfile in a single location in your project when using Multibranch type. Is there a way to configure so I can place the Jenkinsfile somewhere else than in the root of the project under the name Jenkinsfile. There's hope, as there's an option of Fixed Configuration, maybe this is a feature for the future, but I would much appreciate the option, as in the current situation I do not have the option to run everything as one nicely compiled pipeline due to the size of the repo. I'm thinking of having multiple Jenkins jobs against the same repository

How to know which user answered a Jenkins-Pipeline input step?

浪尽此生 提交于 2019-12-05 02:06:55
I have a Jenkinsfile script that tests for the possibility to perform an SVN merge and then asks the user for the permission to commit the merge. I would like to know the username that answers the "input" step in order to write it into the commit message. Is this possibile? This is what hypothetically I would like to do: outcome = input message: 'Merge trunk into branch?', ok: 'Merge' echo "User that allowed merge: ${outcome.user}" The input step got an optional submitterParameter , which allows to specify the key of the returned Map that should contain the user who's submitting the input

Multiple projects sharing a jenkinsfile

放肆的年华 提交于 2019-12-05 01:38:08
问题 I have multiple projects with similar build steps and I am looking into reusing a Jenkinsfile pipeline across these projects. I am having a hard time to find documentation on how to implement such an standard (to my opinion) setup. Here are my requirements : 1) a Jenkinsfile is stored in repo, shared across multiple projects 2) Each project has its own parameter : the project location in the repo. 3) Each project should be independent in Jenkins from a user perspective at least, meaning for