jenkins-pipeline

Jenkins Global environment variables in Jenkinsfile

纵然是瞬间 提交于 2019-12-03 00:11:10
How do I invoke Global environment variables in Jenkinsfile? For example, if I have a variable - name:credentialsId value:xxxx-xxxx-xxxxx-xxxxxxxxx How do I use it in the groovy script? I tried ${credentialsId} , but it didn't work. It will just give error: java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ArtifactoryGradleBuild, ........ In a Jenkinsfile, you have the " Working with the Environment " which mentions: The full list of environment variables accessible from within Jenkins Pipeline is documented at localhost:8080/pipeline-syntax/globals#env, The syntax is $

Load Jenkins Pipeline Shared Library from same repository

纵然是瞬间 提交于 2019-12-02 23:50:18
TL;DR Is there a way to import code into the Jenkinsfile from the local repository (other than the load step)? Why? I've experienced that for complex builds the Jenkinsfile gets kind of bulky and not very maintainable. Now that the build job is code, it would be wonderful to have the same means as for other code. That is, I would like to divide it into smaller (more maintainable) units and unit test them. What I tried shared libraries : allow for dividing our Jenkins Pipeline logic into smaller files in a separate module and even unit test it. However, they need to be in different repository

BadImageFormatException when running unit tests on build server

我只是一个虾纸丫 提交于 2019-12-02 22:13:40
问题 I have a suite of NUnit tests in a project with AnyCPU architecture. Some of these tests use types from an x86 (32-bit) assembly. When I run the tests locally (via ReSharper), they all pass. However, when they're executed on Jenkins by using nunit3-console MyProject.csproj command, the tests that reference the 32-bit assembly fail with BadImageFormatException: System.BadImageFormatException : Could not load file or assembly '...' or one of its dependencies. An attempt was made to load a

How can I reference the Jenkinsfile directory, with Pipeline?

荒凉一梦 提交于 2019-12-02 21:56:35
I have a groovy file, I want to run from the Jenkinsfile. ie. load script.groovy However, I am not sure how I can reference this file if it is stored in the same directory as the Jenkinsfile. I am loading the Jenkinsfile from git. I noticed it creates a folder called workspace@script . It does not place this in the workspace directory. I could hardcode the folder but I am not sure the rules on this and it seems a little redundant to check-out the code again. java.io.FileNotFoundException: /opt/jenkins_home/jobs/my_job/workspace/script.groovy (No such file or directory) By default it loads from

How to re-use previously created workspace across stages

帅比萌擦擦* 提交于 2019-12-02 20:33:00
I am facing an issue where I have two stages defined in my pipeline that both are run on the same node and need to be run in the same workspace. The first of these stages runs on my master node initially, but towards the end of the steps defined has to unstash some files onto a different node. The second stage then just needs to continue on my master, and relies on some modules that were installed from the first stage. Here is my pipeline to better explain: #!groovy pipeline { agent { label 'master' } stages { stage('Build') { // 1. Running on master in /var/lib/jenkins/workspace/_Pipelines

How to run multiple stages on the same node with declarative Jenkins pipeline?

我的未来我决定 提交于 2019-12-02 20:24:12
Goal Run multiple stages of a declarative Jenkins pipeline on the same node. Setup This is just a minimal example to show the problem. There are 2 Windows nodes "windows-slave1" and "windows-slave2" both labeled with the label "windows". NOTE: My real Jenkinsfile cannot use a global agent because there are groups of stages that require to run on different nodes (e.g. Windows vs. Linux). Expected Behaviour Jenkins selects one of the nodes in "Stage 1" based on the label and uses the same node in "Stage 2" because the variable windowsNode was updated to the node selected in "Stage 1". Actual

Use .gdsl file in a Java project in IntelliJ

不羁的心 提交于 2019-12-02 20:20:13
I have a file pipeline.gdsl that contains the Syntax for my Jenkins Pipeline DSL. Following this blog post I put the file into the /src folder of my Java project. When I now edit my Jenkinsfile (residing in the root folder of my project), I don't get any code completion / syntax explanation as I would expect. My project is a Java / Gradle project and I cannot make a Groovy project out of it. Is there some other way to make IntelliJ aware of the .gdsl file and provide code completion? Michael Lihs The problem was, that /src was not marked as a source root folder in my project. Creating a folder

Jenkins Pipeline sh display name/label

穿精又带淫゛_ 提交于 2019-12-02 18:58:33
With Jenkins 2 Pipeline plugin, there's a useful feature allowing a quick overview of the pipeline stages and status of steps, including logging output. However, if you use the "Shell script" (sh) step, there doesn't seem to be a way to label that script with a useful name, so the display merely shows a long list of "Shell Script" (shown in the image below). How can I assign a useful name, or how can I use some other step to accomplish the same effect? Update Feb 2019 : According to gertvdijk's answer below , it is now possible to assign an optional label to the sh step , starting from v2.28,

How to deploy war to tomcat using jenkins pipeline?

岁酱吖の 提交于 2019-12-02 18:52:21
问题 I want to deploy war file using pipeline. What is the correct way to do it . Is there any way to use Deploy to container in pipeline code. The problem with calling catalina.sh or using curl command to deploy using jenkins manager is that I do not find any way to detect successful deployment. Is there any standard way to do that 回答1: In tomcat, there are two options to deploy a war: copy war to webapps folder upload war to /manager/text/deploy http endpoint published by your tomcat Here some

Environment variable in Jenkins Pipeline

我与影子孤独终老i 提交于 2019-12-02 18:50:34
Is there any environment variable available for getting the Jenkins Pipeline Title? I know we can use $JOB_NAME to get title for a freestyle job, but is there anything that can be used for getting Pipeline name? You can access the same environment variables from groovy using the same names (e.g. JOB_NAME or env.JOB_NAME ). From the documentation: Environment variables are accessible from Groovy code as env.VARNAME or simply as VARNAME. You can write to such properties as well (only using the env. prefix): env.MYTOOL_VERSION = '1.33' node { sh '/usr/local/mytool-$MYTOOL_VERSION/bin/start' }