jenkinsfile

Pass Artifact or String to upstream job in Jenkins Pipeline

☆樱花仙子☆ 提交于 2020-12-13 20:57:07
问题 Goal I'm trying to orchestrate a dependency chain using the GitHub organization plugin along with the jenkins pipeline. As the products I'm building have a number of shared dependencies, I'm using nuget packages to manage dependency versioning and updates. However, I'm having trouble getting necessary artifacts/info to the projects doing the orchestration. Strategy On a SCM change any upstream shared libraries should build a nuget package and orchestrate any downstream builds that need new

How do you provide a managed file to a Jenkins build using docker.image?

巧了我就是萌 提交于 2019-12-24 12:12:56
问题 I am trying to use Jenkins Pipelines to build a Maven Java project and deploy its artifacts into Nexus. The Nexus credentials are managed by Jenkins, so I need Jenkins to provide the Maven settings.xml file. My pipeline uses docker to run the build. My Jenkinsfile looks like: node('docker') { git 'git@bitbucket.org:myorg/myproject.git' stage 'Build and Test' // This throws: java.lang.UnsupportedOperationException: Refusing to marshal org.codehaus.groovy.runtime.InvokerInvocationException for

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

佐手、 提交于 2019-12-22 04:57:21
问题 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

How to do simple if-statements inside a declarative pipeline in Jenkins

我的梦境 提交于 2019-12-21 06:49:12
问题 I'm trying to convert my Scripted pipeline to a Declarative Pipeline. Wondering how to do a simple if-statement inside a steps {} block. stage ('Deploy to Docker') { steps { parallel ( "instance1" : { environment { containerId = sh(script: "docker ps --quiet --filter name=${fullDockerImageName}", returnStdout: true).trim() } steps { if (containerId.isEmpty()) { docker.image('some/image').run("--name ${fullDockerImageName}") } } } ) } } This causes the following Exception: WorkflowScript: 201:

Jenkins pipeline code auto trigger with multiple repositories through GitHub Organization Folder Plugin

爱⌒轻易说出口 提交于 2019-12-21 03:35:15
问题 This question is related to the Jenkins job auto trigger with multiple repositories. Defined 3 repo's to checkout in Jenkinsfile. node('slave'){ git clone github.com/owner/abc.git -b ${env.BRANCH_NAME} git clone github.com/owner/def.git -b ${env.BRANCH_NAME} git clone github.com/owner/ghi.git -b ${env.BRANCH_NAME} } Configured Jenkins job using Github organization plugin. In this case my Jenkinsfile is in abc repo and the Jenkins auto trigger is working fine for the abc repo. its not working

How do I tag the current git changeset from inside the Jenkinsfile?

浪尽此生 提交于 2019-12-18 12:28:34
问题 I want to tag the current git changeset and push the tag from inside the Jenkinsfile. If the tag already exists it must be replaced. I want to use this logic in order to tag the build that passed with the snapshot tag, which would be a mobile tag. How can I do this? 回答1: Here is the way I was able to implement this this way, but if you know a better way I am more than willing to hear it. #!groovy stage 'build' node { repositoryCommiterEmail = 'ci@example.com' repositoryCommiterUsername =

How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?

柔情痞子 提交于 2019-12-17 16:27:17
问题 I am trying to find an example of using the Jenkins Copy Artifacts Plugin from within Jenkins pipelines (workflows). Can anyone point to a sample Groovy code that is using it? 回答1: If builds are not running in the same pipeline you can use direct CopyArtifact plugin, here is example: https://www.cloudbees.com/blog/copying-artifacts-between-builds-jenkins-workflow and example code: node { // setup env.. // copy the deployment unit from another Job... step ([$class: 'CopyArtifact', projectName:

How to pass variables from Jenkinsfile to shell command

假装没事ソ 提交于 2019-12-17 16:16:21
问题 I want to use a variable which I am using inside of my Jenkinsfile script, and then pass its value into a shell script execution (either as an environment variable or command line parameter). But the following Jenkinsfile : for (i in [ 'a', 'b', 'c' ]) { echo i sh 'echo "from shell i=$i"' } Gives the output: a from shell i= b from shell i= c from shell i= Desired output is something like: a from shell i=a b from shell i=b c from shell i=c Any idea how to pass the value of i to the shell scipt

How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

戏子无情 提交于 2019-12-17 04:11:45
问题 I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later. sh "ls -l" How can I do this, especially as it seems that you cannot really run any kind of groovy code inside the Jenkinsfile ? 回答1: The latest version of the pipeline sh step allows you to do the following; // Git committer email GIT_COMMIT_EMAIL = sh ( script: 'git --no-pager show -s --format=\'%ae\'', returnStdout: true ).trim() echo

How do I import a Groovy class into a Jenkinfile?

六眼飞鱼酱① 提交于 2019-12-05 23:19:54
问题 How do I import a Groovy class within a Jenkinsfile? I've tried several approaches but none have worked. This is the class I want to import: Thing.groovy class Thing { void doStuff() { ... } } These are things that don't work: Jenkinsfile-1 node { load "./Thing.groovy" def thing = new Thing() } Jenkinsfile-2 import Thing node { def thing = new Thing() } Jenkinsfile-3 node { evaluate(new File("./Thing.groovy")) def thing = new Thing() } 回答1: You can return a new instance of the class via the