jenkins-pipeline

Jenkins continuous delivery pipeline skip stage based on input

谁说胖子不能爱 提交于 2019-12-04 07:52:09
A simplified pipeline will look something like: 1. build 2. unit test 3. deploy to dev 4. integration tests 5. deploy to prod For step #5 I've setup a Jenkins pipeline input command. We won't be deploying to prod on every commit so if we abort all those jobs it will have a big list of grey builds. Is it possible to have a skip option so the build can still be shown as green blue? MaTePe Can't you do something like this, it will be blue/green whatever you choose from input, and you can then run the deployment depending on it too? def deployToProduction = true try{ input 'Deploy to Production'

Prioritise older pipeline runs over newer

笑着哭i 提交于 2019-12-04 07:45:21
In short, is there a way to sort the Jenkins queue based on build/run age instead of how long it has been in the queue? Some background, we've got a pipeline script which do several tasks in parallel and then, at the end have a step which aggregates the results from the parallel tasks. Here's a simplified version: stage ('Do Parrallel stuff') { def par = [:] for (int i = 0; i < 4; i++) { par[i] = {sleep(10)} } parallel par; } stage ('Aggregate') { node { echo "Aggregating stuff" } } Normally, when there's only one ongoing run this works fine. I.e. it runs the four parallel tasks and then do

Jenkins declarative pipeline: What workspace is associated with a stage when the agent is set only for the pipeline?

ぐ巨炮叔叔 提交于 2019-12-04 06:37:34
Here is an example of declarative pipeline where the agent is set for the pipeline but not set in the individual stages: pipeline { agent { node { label 'linux' } } stages { stage('Checkout') { steps { checkout scm } } stage('Build') { steps { sh 'make' } } } } Documentation I've found about scripted pipeline makes it clear that a single workspace will be used within a single node block but multiple node blocks might be allocated multiple workspaces, therefore it is necessary to stash between those steps, use the External Workspace Plugin, etc. if you want to be sure of what's in the workspace

How to add git credentials to the build so it would be able to be used within a shell code?

我与影子孤独终老i 提交于 2019-12-04 06:07:44
I've wrote the following Jenkinsfile: node("master") { def artifactory_creds = 'XXXXXXX' def git_creds = 'XXXXXXX' java = docker.image('openjdk:8-jdk') java.pull() java.inside("-u root --ulimit core=99999999") { withCredentials([ // Use Jenkins credentials ID of artifactory [$class: 'UsernamePasswordMultiBinding', credentialsId: artifactory_creds, usernameVariable: 'A_USER', passwordVariable: 'A_PASS'], [$class: 'UsernamePasswordMultiBinding', credentialsId: git_creds, usernameVariable: 'G_USER', passwordVariable: 'G_PASS'] // Use Jenkins credentials ID of git ]) { sh ''' cd $PWD && git clone

How to add a JDBC driver to a Jenkins pipeline?

て烟熏妆下的殇ゞ 提交于 2019-12-04 05:49:48
I want to create a database within a pipeline script to be used by the deployed app. But first I started testing the connection. I got this problem: java.sql.SQLException: No suitable driver found for jdbc:mysql://mysql:3306/test_db I have the database plugin and the MySQL database plugin installed. How do I get the JDBC driver? import groovy.sql.Sql node{ def sql = Sql.newInstance("jdbc:mysql://mysql:3306/test_db", "user","passwd", "com.mysql.jdbc.Driver") def rows = sql.execute "select count(*) from test_table;" echo rows.dump() } Update after albciff answer: My versions of: Jenkins = 2.19.1

Jenkins + Gradle + Artifactory: Couldn't read generated build info

非 Y 不嫁゛ 提交于 2019-12-04 05:39:33
问题 I'm trying to push my artifacts to Artifactory with Jenkins Pipeline, which call Gradle tool. I am following the examples published on GitHub: Example1 Example2 My Jenkins Pipeline script: stage('Perform Gradle Release') { //ssh-agent required to perform GIT push (when tagging the branch on release) sshagent([git_credential]) { sh "./gradlew clean release unSnapshotVersion -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${release_version} -Prelease.newVersion=${development_version

How to authenticate with a Google Service Account in Jenkins pipeline

一笑奈何 提交于 2019-12-04 05:32:26
I want to use gcloud in Jenkins pipeline and therefore I have to authenticate first with the Google Service account. I'm using the https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin which holds my Private Key Credentials. I'm stuck with loading the credentials into the pipeline: withCredentials([[$class: 'MultiBinding', credentialsId: 'my-creds', variable: 'GCSKEY']]) { sh "gcloud auth activate-service-account --key-file=${GCSKEY}" } I also tried it with from file, but without luck. withCredentials([file(credentialsId:'my-creds', variable: 'GCSKEY')]) { The log says: org.jenkinsci

How do I import a Groovy class into a Jenkinfile?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:10:51
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() } You can return a new instance of the class via the load command and use the object to call "doStuff" So, you would have this in "Thing.groovy" class Thing { def

Jenkins : use withCredentials in global environment section

岁酱吖の 提交于 2019-12-04 04:39:17
I have a Jenkins pipeline with multiple stages that all require the same environment variables, I run this like so: script { withCredentials([usernamePassword(credentialsId: 'COMPOSER_REPO_MAGENTO', passwordVariable: 'MAGE_REPO_PASS', usernameVariable: 'MAGE_REPO_USER')]) { def composerAuth = """{ "http-basic": { "repo.magento.com": { "username": "${MAGE_REPO_USER}", "password": "${MAGE_REPO_PASS}" } } }"""; // do some stuff here that uses composerAuth } } I don't want to have to re-declare composerAuth every time, so I want to store the credentials in a global variable, so I can do something

Can a Jenkins pipeline have an optional input step?

孤街醉人 提交于 2019-12-04 04:26:39
Is it possible to create a Jenkins pipeline with an optional input stage? The below snippet doesn't achieve this goal. Expected behaviour The stage (and therefore the input prompt) should only run for specific branches. Actual behaviour This stage runs for all branches. The when filter is ignored when an input step is used. stage('Approve') { when { expression { BRANCH_NAME ==~ /^qa[\w-_]*$/ } } input { message "Approve release?" ok "y" submitter "admin" parameters { string(name: 'IS_APPROVED', defaultValue: 'y', description: 'Deploy to master?') } } steps { script { if (IS_APPROVED != 'y') {