jenkins-pipeline

How to read subfolders in jenkins pipeline

瘦欲@ 提交于 2021-01-21 10:01:34
问题 I'm trying to write a pipeline jenkins job that loop through the subfolder of a specific directory and launch something. The problem is to access the filesystem. For some reason it does not seems to read the file system at all, neither its own workspace. This is the snippet I'm using node ('label') { workspacePath = '/opt/installersWS' ws(workspacePath){ stage ("test"){ ...some stuff... runtimeBuildDir = new File(workspacePath + "/components") echo runtimeBuildDir.getPath() if

Jenkins + Git: Only build if PR introduced changes in subdirectory

泪湿孤枕 提交于 2021-01-21 09:38:04
问题 We have a large monorepo with multiple projects (A and B) inside of it. I currently have Jenkins setup as a Multibranch Pipelines project that watches the monorepo for PRs. If a PR is created, Jenkins builds both A and B. Now, I want Jenkins to be smarter and only build project A if any change in the PR introduced a change in the A/ directory. This is proving very difficult. when { changeset "A/" } only appears to check if the last commit changed a file in A/ , not if the PR changed a file in

How to run Jenkins Groovy scripts directly from Intellij or Eclipse

眉间皱痕 提交于 2021-01-21 09:36:22
问题 The bounty expires in 6 days . Answers to this question are eligible for a +50 reputation bounty. alex is looking for a canonical answer : The question's author is correct: trying to use Jenkins as a Groovy IDE is a living nightmare. I will award the bounty to anyone who describes how to set up a local IntelliJ (or whatever) environment for executing Groovy scripts that you'd ordinarily execute with Jenkins. It's not obvious because many scripts may contain Jenkins-specific methods that rely

How to run Jenkins Groovy scripts directly from Intellij or Eclipse

守給你的承諾、 提交于 2021-01-21 09:35:13
问题 The bounty expires in 6 days . Answers to this question are eligible for a +50 reputation bounty. alex is looking for a canonical answer : The question's author is correct: trying to use Jenkins as a Groovy IDE is a living nightmare. I will award the bounty to anyone who describes how to set up a local IntelliJ (or whatever) environment for executing Groovy scripts that you'd ordinarily execute with Jenkins. It's not obvious because many scripts may contain Jenkins-specific methods that rely

Passing parameters from Jenkinsfile to a shared library

情到浓时终转凉″ 提交于 2021-01-21 08:45:27
问题 I have several components(code projects with their own Bitbucket repositories) and each of them has a Jenkinsfile as follows: properties([parameters([string(defaultValue: "", description: "List of components", name: 'componentsToUpdate'), string(defaultValue: "refs%2Fheads%2Fproject%2Fintegration", description: "BuildInfo CommitID", name: 'commitId'), string(defaultValue: "", description: "Tag to release, e.g. 1.1.0-integration", name: 'releaseTag'), string(defaultValue: "", description:

Jenkins: get environment variables in the body of a global function

て烟熏妆下的殇ゞ 提交于 2021-01-21 05:33:46
问题 I have a shared global function on PublishGitHub.groovy looks like this: #!/usr/bin/env groovy def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config echo "\u001B[32mINFO: Publishing...\u001B[m" body() echo "\u001B[32mINFO: End Publish...\u001B[m" } And a code on my JenkinsFile: environment { VERSION = "v1.3.${env.BUILD_NUMBER}" } stages { stage ('Publish WebAPI'){ steps{ echo "\u001B[32mINFO: Start Publish...\u001B[m" PublishGitHub{ echo "This

Jenkins: get environment variables in the body of a global function

落花浮王杯 提交于 2021-01-21 05:33:24
问题 I have a shared global function on PublishGitHub.groovy looks like this: #!/usr/bin/env groovy def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config echo "\u001B[32mINFO: Publishing...\u001B[m" body() echo "\u001B[32mINFO: End Publish...\u001B[m" } And a code on my JenkinsFile: environment { VERSION = "v1.3.${env.BUILD_NUMBER}" } stages { stage ('Publish WebAPI'){ steps{ echo "\u001B[32mINFO: Start Publish...\u001B[m" PublishGitHub{ echo "This

Is it impossible to checkout a different branch in Jenkinsfile?

独自空忆成欢 提交于 2021-01-20 17:51:33
问题 I have two branches on BitBucket: master and develop . I've also got a BitBucket Team Folder job configured on my Jenkins server to build that repository. On the develop branch there's the following Jenkinsfile: node { stage('Checkout') { checkout scm } stage('Try different branch') { sh "git branch -r" sh "git checkout master" } } When Jenkins runs it, the build fails when it attempts to checkout master : [Pipeline] stage [Pipeline] { (Try different branch) [Pipeline] sh [e_jenkinsfile-tests

How to exclude jenkins files from scm polling on a jenkins job

孤街醉人 提交于 2021-01-20 07:30:34
问题 I'm working with declarative pipeline syntax. My jenkins files are stored on a git hub repository, separated from the code to build, so I set up the jenkins job to get the pipeline script from scm, selecting my git repo on master branch. Within my pipeline script I'm using the checkout step to get my real code from another source (an RTC repository in my case, but I suppose another git repository would be the same scenario). Everything works well and if I enable to trigger the build by

The same shell command behaves differently if it is located in different stages of Jenkins pipeline

怎甘沉沦 提交于 2021-01-07 06:38:15
问题 I'm trying to execute following stage in Jenkins pipeline stage('RUN') { steps{ dir("airflow-dags") { sh "find ./volumes/dags/ -maxdepth 1 -name '*.py' -print0" } } } If this stage is located in the last position (after deploy and other stuff) it returns nothing: 08:56:58 Running in /home/jenkins/workspace/QA_deploy_Docker/airflow-dags [Pipeline] { [Pipeline] sh 08:56:59 + find ./volumes/dags/ -maxdepth 1 -name '*.py' -print0 [Pipeline] } [Pipeline] // dir [Pipeline] } [Pipeline] // stage If