jenkins-pipeline

Matrix configuration with Jenkins pipelines

放肆的年华 提交于 2019-11-30 00:02:53
The Jenkins Pipeline plugin (aka Workflow) can be extended with other Multibranch plugins to build branches and pull requests automatically. What would be the preferred way to run multiple configurations? For example, building with Java 7 and Java 8. This is often called matrix configuration (because of the multiple combinations such as language version, framework version, ...) or build variants. I tried: executing them serially as separate stage steps. Good, but takes more time than necessary. executing them inside a parallel step, with or without node s allocated inside them. Works but I

How to create methods in Jenkins Declarative pipeline?

感情迁移 提交于 2019-11-29 23:53:08
In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how? Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script: pipeline { agent any stages { stage('Test') { steps { whateverFunction() } } } } void whateverFunction() { sh 'ls /' } You can create a groovy function like this and save it in your git which should be configured as managed library (Configure it in jenkins too): /path/to/repo

Load file with environment variables Jenkins Pipeline

谁说我不能喝 提交于 2019-11-29 22:24:08
I am doing a simple pipeline: Build -> Staging -> Production I need different environment variables for staging and production, so i am trying to source variables. sh 'source $JENKINS_HOME/.envvars/stacktest-staging.sh' But it returns Not found [Stack Test] Running shell script + source /var/jenkins_home/.envvars/stacktest-staging.sh /var/jenkins_home/workspace/Stack Test@tmp/durable-bcbe1515/script.sh: 2: /var/jenkins_home/workspace/Stack Test@tmp/durable-bcbe1515/script.sh: source: not found The path is right, because i run the same command when i log via ssh, and it works fine. Here is the

How to send Slack notification after Jenkins pipeline build failed?

大兔子大兔子 提交于 2019-11-29 22:15:23
I have a pipeline groovy script in Jenkins v2.19. Also I have a "Slack Notification Plugin" v2.0.1 and "Groovy Postbuild Plugin". I have successfully send a message "build started" and "build finished" (if it had). When some build step failed – how I can send a message "Build failed" to the Slack channel? You could do something like this and use a try catch block. Here is some example Code: node { try { notifyBuild('STARTED') stage('Prepare code') { echo 'do checkout stuff' } stage('Testing') { echo 'Testing' echo 'Testing - publish coverage results' } stage('Staging') { echo 'Deploy Stage' }

Can I use a Closure to define a stage in a Jenkins Declarative Pipeline?

独自空忆成欢 提交于 2019-11-29 22:06:18
问题 I'm trying to do something like this: def makeStage = { stage('a') { steps { echo 'Hello World' } } } pipeline { agent none stages { makeStage() } } But it gives me this exception: WorkflowScript: 11: Expected a stage @ line 11, column 5. makeStage() ^ Is it possible to define a stage as a external closure and if so - how? 回答1: You can't define stages outside the declarative pipeline. The main purpose of declarative pipeline is to provide simplified and opinionated syntax so you can focus on

How to trigger a Jenkins 2.0 Pipeline job from a GitHub pull request

我与影子孤独终老i 提交于 2019-11-29 20:41:17
It looks like the GitHubPullRequestBuilder is not compatible with Jenkins v2.0 pipeline jobs. How do you configure a pipeline job to be triggered from a GitHub pull request event? The documentation on this topic is sparse and I cannot find any examples of this. Or is it better to create a web-hook in GitHub to trigger the pipeline job on the PR event? The most straightforward way to use Pipeline with GitHub pull requests is to put the script into your repository under the name Jenkinsfile and then install the GitHub Branch Source plugin. Documentation I had similar issue. Here’s what worked

Jenkins how to create pipeline manual step

与世无争的帅哥 提交于 2019-11-29 20:20:17
Prior Jenkins2 I was using Build Pipeline Plugin to build and manually deploy application to server. Old configuration: That works great, but I want to use new Jenkins pipeline, generated from groovy script (Jenkinsfile), to create manual step. So far I came up with input jenkins step. Used jenkinsfile script: node { stage 'Checkout' // Get some code from repository stage 'Build' // Run the build } stage 'deployment' input 'Do you approve deployment?' node { //deploy things } But this waits for user input, noting that build is not completed. I could add timeout to input , but this won't allow

Can I import a groovy script from a relative directory into a Jenkinsfile?

烂漫一生 提交于 2019-11-29 19:08:01
问题 I've got a project structured like this: / / Jenkinsfile / build_tools / / pipeline.groovy # Functions which define the pipeline / reporting.groovy # Other misc build reporting stuff / dostuff.sh # A shell script used by the pipeline / domorestuff.sh # Another pipeline supporting shell-script Is it possible to import the groovy files in /build_tools so that I can use functions inside those 2 files in my Jenkinsfile? Ideally, I'd like to have a Jenkins file that looks something like this

What is the best way to change application configurations in a CI environment

我与影子孤独终老i 提交于 2019-11-29 18:05:38
I am currently doing a POC on Jenkins pipeline to figure out how to configure my product in a CI environment. The requirements of the pipeline are: Checkout code from SVN Compile the program Deploy to a predefined location on the server Change DB configurations (& maybe even other configs not identified yet) to point to the appropriate DB Execute the program Execute QA process to validate the output I am currently having difficulty in achieving Point 4 above. All DB-related configurations reside in a database.xml file per program & a program can connect to 1 or more DBs. Given that developers

How to direct jenkins pipeline stage execution to a particular node agent derived from parameter?

北城余情 提交于 2019-11-29 17:26:20
I have multipe Jenkins node agents, including "master", "tiering_agent1", and "cirrus". I am trying to set the node on which a Stage is executed by a parameters{} setting. I have this pipeline code def BuildAgentLabel='tiering_agent1' pipeline { agent { label 'master' } parameters { string( name: 'NEW_LABEL', defaultValue: '', description: '' ) } stages { stage( 'Init') { steps { script { if ( params.NEW_LABEL != '' ){ echo "Setting BuildAgentLabel to '${params.NEW_LABEL}'" BuildAgentLabel = params.NEW_LABEL echo "BuildAgentLabel is now '${BuildAgentLabel}'" } } } } stage( "Build") { agent {