jenkins-pipeline

How to add a JDBC driver to a Jenkins pipeline?

﹥>﹥吖頭↗ 提交于 2019-12-06 02:02:21
问题 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

npm install fails in Jenkins pipeline

不羁岁月 提交于 2019-12-06 01:48:56
I've created a docker images to be able to run node >= 7.9.0 and monogodb for testing in Jenkins. Some might argue that testing with mongodb is not correct approach but the app uses it extensively and I have some complex updates and deletes so I need it there. Docker file is under dockerfiles/test/Dockerfile in my github repo. When using the pipeline syntax the docker images is built successfully but I can't do sh 'npm install' or sh 'npm -v' in the steps of the pipeline. The docker images is tested and if I build it locally and run it I can do the npm install there. sh 'node -v' runs

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

筅森魡賤 提交于 2019-12-06 01:44:57
问题 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

Is there a way to move the entire post {} build section in Jenkinsfile to the global pipeline library?

天大地大妈咪最大 提交于 2019-12-06 01:36:53
I'm relatively new to Jenkins pipelines, but having implemented already a few, I've realised I need to start using jenkins shared library before I go mad. Have already figured out how to define some repetitive steps in the library and call them with less clutter from Jenkinsfile, but not sure if the same thing can be done for the entire post build section (thought I've read about to how to define the entire pipeline in the lib and similar ), as this is pretty much static end of every single pipeline code: @Library('jenkins-shared-library')_ pipeline { agent none stages { stage ('System Info')

Capturing shell script output from Jenkins Pipeline

…衆ロ難τιáo~ 提交于 2019-12-05 23:51:55
I am trying to extract git branch and commit information in my Jenkinsfile as following: def commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() def branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() I am trying to print it afterwards like this: println("Branch: ${branch}, Commit: ${commit}") Instead of getting real values, I am left with this: Branch: org.jenkinsci.plugins.pipeline.modeldefinition.ClosureModelTranslator@545511bf, Commit: org.jenkinsci.plugins.pipeline.modeldefinition.ClosureModelTranslator@545511bf Am I doing something wrong and

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

How to authenticate with a Google Service Account in Jenkins pipeline

给你一囗甜甜゛ 提交于 2019-12-05 23:16:06
问题 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.

Template docker agent in jenkins Declarative pipeline

亡梦爱人 提交于 2019-12-05 22:44:14
I have a Jenkinsfile for a declarative pipeline that uses docker agents. A number of the steps use a docker agent and it is a bit repetitive adding the same agent for these steps e.g. pipeline { agent any stages { stage('Stage 1') { steps { //Do something } } stage('Stage 2') { agent { docker { image 'jenkins/jenkins-slave:latest' reuseNode true registryUrl 'https://some.registry/' registryCredentialsId 'git' args '-v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -e HOME=${WORKSPACE}' } } steps { //Do something } } stage('Stage 3') { steps { //Do something } } stage('Stage 4') { agent {

Set a stage status in Jenkins Pipelines

只谈情不闲聊 提交于 2019-12-05 21:44:41
问题 Is there any way in a scripted pipeline to mark a stage as unstable but only show that stage as unstable without marking every stage as unstable in the output? I can do something like this: node() { stage("Stage1") { // do work (passes) } stage("Stage2") { // something went wrong, but it isn't catastrophic... currentBuild.result = 'UNSTABLE' } stage("Stage3") { // keep going... } } But when I run this, Jenkins marks everything as unstable... but I'd like the first and last stages to show

Passing variables to powershell script block in a jenkins pipeline

亡梦爱人 提交于 2019-12-05 20:55:24
Is there a way to use groovy variables inside a powershell script? My sample script is as following.. node { stage('Invoke Installation') { def stdoutpowershell def serverName = env.fqdn withEnv(['serverName = $serverName']) { echo "serverName : $serverName" stdoutpowershell = powershell returnStdout: true, script: ''' write-output "Server is $env:serverName" ''' } } You can't interpolate variables in single quotes or triple-single-quotes. Use triple-double-quotes: stdoutpowershell = powershell returnStdout: true, script: """ write-output "Server is $envserverName" """ 来源: https:/