jenkins-pipeline

Get parameters of Jenkins build by job name and build id

僤鯓⒐⒋嵵緔 提交于 2019-12-12 18:03:50
问题 I am using Jenkins Pipeline plugin and I need to get all parameters of particular build by its id and job name from other job. So, basically i need something like this. def job = JobRegistry.getJobByName(jobName) def build = job.getBuild(buildId) Map parameters = build.getParameters() println parameters['SOME_PARAMETER'] 回答1: I figured it out. I can retrieve parameters like this def parameters = Jenkins.instance.getAllItems(Job) .find {job -> job.fullName == jobName } .getBuildByNumber

Jenkins Pipeline - Pass Artifact URL between stages

删除回忆录丶 提交于 2019-12-12 17:39:58
问题 My usecase is to build a Java job , deploy a tar.gz.zip to nexus and pass on this artifact URL to further stages. I am using the below command in a script that does other validation: mvn -B clean deploy -U package deploy:deploy -DskipNexusStagingDeployMojo=true -DaltDeploymentRepository=dev-snapshots::default::https://<myrepo.com> Below would be my stages: stage('publish'){ //push to Nexus } stage('processing'){ // get the artifact url from above step } I don't want to use "archiveartifacts"

Access custom environment variables in jelly template

独自空忆成欢 提交于 2019-12-12 12:15:27
问题 With Jenkins pipeline you are able to set any environment variable through Global Variable called - env . Jelly template in it's turn gives you ability to access Jenkins API including hudson.model.AbstractBuild and hudson.model.AbstractProject objects. Here are the snippets that I use: Jenkinsfile: node { env.MYVAR = 'My variable' emailext body: ${JELLY_SCRIPT, template="myTemplate"}, subject: 'MySubject', to: 'me' } Jelly template (myTemplate): <?jelly escape-by-default='true'?> <!DOCTYPE

How can I prevent IntelliJ IDEA from reassigning file type associations at startup?

帅比萌擦擦* 提交于 2019-12-12 11:22:28
问题 I'm using IntelliJ IDEA Ultimate 18.1 and Jenkinsfile support is awful. Thankfully, treating the file as Groovy is a workaround I can live with. This involves Removing the Jenkinsfile association Adding Jenkinsfile under the Groovy group The problem is every time IDEA starts up fresh, it will remove Jenkinsfile association and, since (1) the original association has been removed, treat these files as plain text. File type recognized: File extension Jenkinsfile was reassigned to Jenkins file

How to set Artifactory discardOldBuilds to true in a Jenkinsfile?

↘锁芯ラ 提交于 2019-12-12 11:06:15
问题 I am working on implementing a build job using Jenkins Multibranch Pipelines. The final stage is uploading the build output to Artifactory. When configuring a standalone job via the interface, there is an option to "Discard old builds from Artifactory" which allows me to only keep the same number of builds as specified in "Max # of builds to keep" setting. The upload stage in my Jenkinsfile is configured like this: https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+-+Working+With+the

Jenkins to run Maven build on Linux or Windows

与世无争的帅哥 提交于 2019-12-12 10:55:35
问题 I have a Maven build of a Java application that runs successfully on either Linux or Windows by typing the identical command mvn install . However, using the Jenkinsfile method of setting up this build, on Linux that file needs to contain sh mvn install and on windows bat mvn install . If paths and tools are configured appropriately on Windows, log shows: [Pipeline] sh [C:\tools\jenkins\workspace\DSL\master] Running shell script sh: C:\tools\jenkins\workspace\DSL\master@tmp\durable-60527040

Jenkins CopyArtifact step - Unable to find project for artifact copy

懵懂的女人 提交于 2019-12-12 10:42:54
问题 Based on this post trying to test the pipe line code in my enviroment. But its giving below error message. how to fix his pipeline code? ERROR: Unable to find project for artifact copy: test This may be due to incorrect project name or permission settings; see help for project name in job configuration. Finished: FAILURE How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)? pipeline { agent any stages { stage ('push artifact') { steps { sh '[ -d archive ] ||

How can I isolate my Jenkins pipeline Groovy shared library classloader?

北城余情 提交于 2019-12-12 10:36:27
问题 I have a Groovy library made available as a Global shared library: package com.example @Grab(group="org.apache.httpcomponents", module="httpclient", version="[4.5.3,)") import org.apache.http.HttpHost import org.apache.http.impl.client.HttpClients class MyClass implements Serializable { static def run() { return HttpClients.custom() .setProxy(new HttpHost("proxy.example.com", 3128)) .build() } static def debug() { return (""" this: ${this.classLoader.class.toString()} ${this.classLoader

List files on the workspace on a Jenkins Pipeline

江枫思渺然 提交于 2019-12-12 10:29:01
问题 I'm trying to list files in the workspace in a Jenkins Pipeline, so that I can use that to produce appropriate parallel tasks. While I could simply use sh ls > files and read that, I want File objects which I can filter further with more complex logic. In fact, Files.listFiles(FileFilter) would be ideal. However, I can't get the list of files at all. First, I had to resort to some weird stuff to simply find out the current work directory for the build: sh 'pwd > workspace' workspace =

How to call functions in one Jenkins Shared Library from another

孤人 提交于 2019-12-12 09:45:02
问题 I have two separate libraries (Library A and Library B), I have defined them on the jenkins configuration so they can be both called from the pipeline. From Library A I would like to call some functions/methods that are defined in Library B. My logic tells me that I need to import and probably create an instance of Library B inside Library A before I can have access to any of Library B methods. But I have not been successful. I am no expert in Java, however any guidance is greatly appreciated