jenkins-pipeline

Checkout Jenkins Pipeline Git SCM with credentials?

空扰寡人 提交于 2019-11-28 16:28:25
I was following this tutorial : node { git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git' ... } However it doesn't tell how to add credentials. Jenkins does have specific "Credentials" section where you define user user&pass, and then get ID for that to use in jobs, but how do I use that in Pipeline instructions? I tried with: git([url: 'git@bitbucket.org:company/repo.git', branch: 'master', credentialsId: '12345-1234-4696-af25-123455']) no luck: stderr: Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct

Curl request from command line and via Groovy script

♀尐吖头ヾ 提交于 2019-11-28 14:37:49
I am facing an issue which i do not understand, I have written a simple groovy script that when called from the command line works as expected #!/usr/bin/env groovy def jsonParse(def json) { new groovy.json.JsonSlurperClassic().parseText(json) } def ticketNumbers = ["MYSTATS-2695", "MYSTATS-2694"] ArrayList<String> jiraLinks = new ArrayList<String>(); for(int i =0; i < ticketNumbers.size(); i++) { def jira_json = "curl -o /dev/null -X GET -H Content-Type: application/json --cert-type PEM --key-type PEM -E /Users/Jenkins/.jenkins/workspace/certificates/cert.pem --key /Users/Jenkins/.jenkins

How can I test a change made to Jenkinsfile locally?

时光怂恿深爱的人放手 提交于 2019-11-28 13:42:33
问题 When writing jenkins pipelines it seems to be very inconvenient to commit each new change in order to see if it works. Is there a way to execute these locally without committing the code? 回答1: You cannot execute Pipeline script locally, since its whole purpose is to script Jenkins. (Which is one reason why it is best to keep your Jenkinsfile short and limited to code which actually deals with Jenkins features; your actual build logic should be handled with external processes or build tools

Jenkins build fail for PR from GitHub

偶尔善良 提交于 2019-11-28 12:42:24
I'm using jenkins pipeline to build my github project. When I raise a pull request (PR) on GitHub, its creating a job "pr-head" which fails all the time with below error Let me know if you have any suggestions for this Even the answers in Git PullRequest job failed. Couldn't find any revision to build. Verify the repository and branch configuration for this job did not solve my problem Update 2019/03/22: Quick anser Use a refspec which fits your git server's PR handling. E.g. for Bitbucket that could be: +refs/pull-requests/*/merge:refs/remotes/@{remote}/PR-* Full Answer There is an open

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

吃可爱长大的小学妹 提交于 2019-11-28 12:23:55
问题 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

How to read properties file from Jenkins 2.0 pipeline script

…衆ロ難τιáo~ 提交于 2019-11-28 12:01:58
I am attempting to write a pipeline script to use with Jenkins 2.0 to replicate our existing build. This original build used the envInject plugin to read a Java properties file, but I can't see how to do this from the pipeline Groovy script. I have Googled and found the following, but it doesn't work (FileNotFoundException): Properties props = new Properties() File propsFile = new File('./Builder/project.properties') props.load(propsFile.newDataInputStream()) Thanks! Mike Kingsbury I just fought with this yesterday and today. I wish the availability of this was easier to find. Grab the '

How to configure a Jenkins 2 Pipeline so that Jenkinsfile uses a predefined variable

℡╲_俬逩灬. 提交于 2019-11-28 11:02:21
问题 I have several projects that use a Jenkinsfile which is practically the same. The only difference is the git project that it has to checkout. This forces me to have one Jenkinsfile per project although they could share the same one: node{ def mvnHome = tool 'M3' def artifactId def pomVersion stage('Commit Stage'){ echo 'Downloading from Git...' git branch: 'develop', credentialsId: 'xxx', url: 'https://bitbucket.org/xxx/yyy.git' echo 'Building project and generating Docker image...' sh "$

How to import a file of classes in a Jenkins Pipeline?

╄→гoц情女王★ 提交于 2019-11-28 09:29:52
问题 I have a file that contains classes. Example : abstract class TestBase { String name abstract def fTest() def bobby(){ return "bobby" } } class Test extends TestBase { def fTest(){ return "hello" } } class Test2 extends TestBase { def fTest(){ return "allo" } def func(){ return "test :)" } } I want to import the file in my Jenkins pipeline script, so I can create an object of one of my class. For example : def vTest = new Test() echo vTest.fTest() def vTest2 = new Test2() echo vTest2.func()

Using FilePath to access workspace on slave in Jenkins pipeline

依然范特西╮ 提交于 2019-11-28 08:40:26
I need to check for the existence of a certain .exe file in my workspace as part of my pipeline build job. I tried to use the below Groovy script from my Jenkinsfile to do the same. But I think the File class by default tries to look for the workspace directory on jenkins master and fails. @com.cloudbees.groovy.cps.NonCPS def checkJacoco(isJacocoEnabled) { new File(pwd()).eachFileRecurse(FILES) { it -> if (it.name == 'jacoco.exec' || it.name == 'Jacoco.exec') isJacocoEnabled = true } } How to access the file system on slave using Groovy from inside the Jenkinsfile? I also tried the below code.

Jenkins Workflow Checkout Accessing BRANCH_NAME and GIT_COMMIT

北城余情 提交于 2019-11-28 08:25:05
I cannot seem to extract $GIT_COMMIT and $BRANCH_NAME from a Jenkins Workflow Checkout step. I would like to be able to send this information through to my Gradle scripts in order to pass it onto external sources such as Static analysis etc. Currently I try to run this: checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[credentialsId: '2b74a351-67d5-4d00-abd3-49842a984201', url: 'ssh://git@corporate.com:repo.git']]]) And I would like to achieve the following or something similar: // Specified variables that can be reused def branch = ${BRANCH_NAME} def commit = $