Posts

Showing posts with the label Jenkins

Add Build Parameter In Jenkins Build Schedule

Answer : Basically, with the 'Build periodically' option you can't schedule a Jenkins job with parameters. However, to schedule a job at different times that needs to use different environments, you have to use the parameterized-scheduler plugin or search for it in (Manage Jenkins -> Manage Plugins -> Parameterized Scheduler). Examples: # Parameter1 H/15 * * * * %Parameter1 # Parameter2 H/30 * * * * %Parameter2 Remember you have to have your parameters already setup because the plugin is visible only for jobs with parameters. The Node and Label parameter plugin can help since it allows you to select individual nodes assuming your different servers qa1 and qa2 are already configured. Hope that clarifies things for you. With the native Jenkins crontab, it's not possible. But it should be possible with this plugin: https://github.com/jwmach1/parameterized-scheduler You have to fork the repo and build this plugin + do a manual installation. Th...

BitBucket WebHook Jenkins

Answer : SPECIFIC solution for Jenkins CI server--Webhook to Jenkins for Bitbucket plugin has been commercialized in latest version of Bit-Bucket and the current price is around $4800 which was earlier a free offering, because of this, guys who want to save their bucks, can go to the alternative solution by using webhooks feature of bit-bucket:- Steps to create a webhook:- BitBucket Side 1) Go to your bitbucket repo, click on Repository Setting, under WORKFLOW got for WEBHOOKS option and create a webhook. a) creation of webhook:- URL https://JenkinsserverURL/git/notifyCommit?url=https://bitbucket.repository-link/repository.git b) In the name tab, give any name of your choice c) click on TEST CONNECTION before saving it. Make sure you get http status 200 d) View details your logs, check your request and response is correct. Things to take care of from Jenkins Side:- 1) Make sure repository mentioned in bitbucket webhook is used in Jenkins job. 2) In SCM option, act...

"Build Periodically" With A Multi-branch Pipeline In Jenkins

Answer : If you use a declarative style Pipeline and only want to trigger the build on a specific branch you can do something like this: String cron_string = BRANCH_NAME == "master" ? "@hourly" : "" pipeline { agent none triggers { cron(cron_string) } stages { // do something } } Found on Jenkins Jira If you are using a declarative style Jenkinsfile then you use the triggers directive. pipeline { agent any triggers { cron('H 4/* 0 0 1-5') } stages { stage('Example') { steps { echo 'Hello World' } } } } I was able to find an example illustrating this an discarding old builds, which is also something I wanted. Jenkinsfile in jenkins-infra/jenkins.io: properties( [ [ $class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '10'] ], ...

Cobertura Code Coverage Report For Jenkins Pipeline Jobs

Answer : There is a way to add a pipeline step to publish your coverage report but it doesn't show under the BlueOcean interface. It will show fine in the normal UI. pipeline { agent any stages { ... } post { always { junit '**/nosetests.xml' step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/coverage.xml', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false]) } } } Note that one of the parameters to the Cobertura plugin is the XML that it will use ('**/coverage.xml' in the example). If you are using python, you will want to use something like: nosetests --with-coverage --cover-xml --cover-package=pkg1,pkg2 --with-xunit test Nowadays you can also use the cobertura command directly in a Jenkinsfile stage ("Extract...

Archive Artifacts In Jenkins

Answer : You cannot remove the 'prefix' of a path using just the archive artifacts setting. (Some of the upload extensions do support this - the Publish over FTP plugin for example) If you really need this a simple solution is to add an extra build step that copies your Debug folder to the root of the project workspace. A cleaner way might be to have a stage dedicated to producing artifacts, set up with the appropriate working directory: stage('Release') { steps { dir('MyApp1/MyApp1/bin/Debug') { archiveArtifacts artifacts: '**', fingerprint: true } } }

Authenticate Jenkins CI For Github Private Repository

Answer : Perhaps GitHub's support for deploy keys is what you're looking for? To quote that page: When should I use a deploy key? Simple, when you have a server that needs pull access to a single private repo. This key is attached directly to the repository instead of to a personal user account. If that's what you're already trying and it doesn't work, you might want to update your question with more details of the URLs being used, the names and location of the key files, etc. Now for the technical part: How to use your SSH key with Jenkins? If you have, say, a jenkins unix user, you can store your deploy key in ~/.ssh/id_rsa . When Jenkins tries to clone the repo via ssh, it will try to use that key. In some setups, you cannot run Jenkins as an own user account, and possibly also cannot use the default ssh key location ~/.ssh/id_rsa . In such cases, you can create a key in a different location, e.g. ~/.ssh/deploy_key , and configure ssh ...

Cannot Use ReadMavenPom In Jenkinsfile

Answer : I needed to install the pipeline-utility-steps plugin.

Can I Define Multiple Agent Labels In A Declarative Jenkins Pipeline?

Answer : You can see the 'Pipeline-syntax' help within your Jenkins installation and see the sample step "node" reference. You can use exprA||exprB : node('small||medium') { // some block } This syntax appears to work for me: agent { label 'linux && java' } EDIT: I misunderstood the question. This answer is only if you know which specific agent you want to run for each stage. If you need multiple agents you can declare agent none and then declare the agent at each stage. https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents From the docs: pipeline { agent none stages { stage('Build') { agent any steps { checkout scm sh 'make' stash includes: '**/target/*.jar', name: 'app' } } stage('Test on Linux') { agent { label ...

Checkout Jenkins Pipeline Git SCM With Credentials?

Answer : You can use the following in a pipeline: git branch: 'master', credentialsId: '12345-1234-4696-af25-123455', url: 'ssh://git@bitbucket.org:company/repo.git' If you're using the ssh url then your credentials must be username + private key. If you're using the https clone url instead of the ssh one, then your credentials should be username + password. To explicitly checkout using a specific credentials stage('Checkout external proj') { steps { git branch: 'my_specific_branch', credentialsId: 'my_cred_id', url: 'ssh://git@test.com/proj/test_proj.git' sh "ls -lat" } } To checkout based on the configred credentials in the current Jenkins Job stage('Checkout code') { steps { checkout scm } } You can use both of the stages within a single Jenkins file. If you want...

Checkout SVN With Credentials In Jenkins Pipeline?

Image
Answer : You can use the Snippet Generator for General SCM step. This displays the familiar Subversion configuration options, and takes credentials as parameter as usual. The Snippet Generator will produce a tad ugly representation of your parameter selections and looks something like this: checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[credentialsId: '34761a89-1402-47d7-96e2-aec22ffdc50b', depthOption: 'infinity', ignoreExternalsOption: true, local: 'cable_branch', remote: "https://trac.nci.org.au/svn/cable/branches/$SVN_...