We have a large SVN repository and I would like to do a sparse checkout on Jenkins. I do understand the concept of sparse checkouts and having it locally I can get things to work as I would like to have it. Doing things on Jenkins however and running it repeatedly I can't get to work.
I have a repo structure as follows
trunk\file.txt
trunk\FolderA
trunk\FolderB
trunk\FolderC
trunk\FolderD
I would like to checkout and update
trunk\file.txt
trunk\FolderA
trunk\FolderB
but NOT
trunk\FolderC
trunk\FolderD
My pipeline code is as follows
checkout([$class: 'SubversionSCM',
additionalCredentials: [[credentialsId: strCredentialsId, realm: strRealm]],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '', filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [
[
remote: "${strRepoPath}/trunk",
local: "${softwarePath}",
depthOption: 'unknown',
credentialsId: strCredentialsId,
cancelProcessOnExternalsFail: true,
ignoreExternalsOption: false
],
[
remote: "${strRepoPath}/trunk/FolderA",
local: "${softwarePath}/FolderA",
depthOption: 'infinity',
credentialsId: strCredentialsId,
cancelProcessOnExternalsFail: true,
ignoreExternalsOption: false
],
[
remote: "${strRepoPath}/trunk/FolderB",
local: "${softwarePath}/FolderB",
depthOption: 'infinity',
credentialsId: strCredentialsId,
cancelProcessOnExternalsFail: true,
ignoreExternalsOption: false
]
],
quietOperation: false,
workspaceUpdater: [$class: 'UpdateWithCleanUpdater']])
Whenever I run this code the first time, everything looks as expected. However, when Jenkins runs it the following times, the UpdateWithCleanUpdater causes that FolderA and FolderB get first deleted and then checked out again. The result is still correct, however, it takes much longer that I would like it to take and longer than necessary.
I would like to keep the UpdateWithCleanUpdater because I want Jenkins to clean up files generated in the previous run.
Is there any solution to this using the Jenkins SVN plugin? How would I do this "manually", i.e. do a checkout the first time, clean up and only update the following times, and still do automatic Jenkins runs based on change detection on the SVN repo?
Thanks in advance!
Now that is a very narrow issue.
I'd say, either you replace the UpdateWithCleanUpdater with a manual script (by calling your local svn client; some examples here); or you could fork or contribute to the Jenkins SVN plugin.
On the trunk you have:
depthOption: 'unknown',
Shouldn't the value be 'empty'?
Yet, while what that might avoid the "FolderA and FolderB get first deleted and then checked out again", so I doubt that you would really get the "sparse checkout" in this way. It will be rather a "normal checkout into another SVN workspace".
As a workaround you can consider using svn:externals: Create a folder trunk/JenkinsWorkspace/trunk, and set svn:externals property with a content like:
^/trunk/FolderA FolderA
^/trunk/FolderB FolderB
^/trunk/file.txt file.txt
Then, in Jenkins you would just have a single checkout from ${strRepoPath}/JenkinsWorkspace.
Related
I'm new to Jenkins and I'm trying to understand the following step in Jenkins pipeline line by line:
checkout scm
dir("some_directory") {
checkout(
changelog: false,
poll: false,
scm: [
$class : 'GitSCM',
branches : [[name: SOME_BRANCH_NAME]],
doGenerateSubmoduleConfigurations: false,
extensions : [[$class: 'CloneOption', depth: 0, honorRefspec: true, reference: '', shallow: false]],
submoduleCfg : [],
userRemoteConfigs : [[url: SOME_URL]]
]
)
sh 'pwd; ls'
}
From the research I've done I understood that
checkout scm dir("some_directory")
'dir' creates a folder in workspace if it doesn't exist, and git project gets checked out into this directory
checkout(
changelog:false,
poll:false,
scm: [...]
)
this block of code specifies git parameters of the git project that is being checked out into the directory specified above.
This is so far what I understood, can someone please lt me know if my understanding is correct? And possibly add more details to it.
Also, I am confused with the current code syntax. Would it make any difference if I rewrite the top few lines as:
checkout scm dir("some_directory")(
changelog: false,
poll: false,
etc.
)
instead of using 'checkout' two times.
I am using a declarative pipeline and groovy scripts to check out my branch. I check out using the checkout step:
[$class: 'GitSCM',
branches: [[name: "${selectedBranch}"]],
browser: [$class: 'BitbucketWeb', repoUrl: 'myURL'],
doGenerateSubmoduleConfigurations: false,
extensions:
[[$class: 'CloneOption', noTags: false, reference: "${cloneReference}", shallow: true, timeout: 5]],
submoduleCfg: [],
userRemoteConfigs: [[url: "${projectDetails.repositoryAddress}"]]])
And that works great. However when looking at the change history, it shows the history for my shared library NOT for the actual branch checked out. This means I'm getting all the history for my jenkins groovy changes, but no history for the actual solution/source being built. I cannot figure out a way to overcome this.
On my Jenkins job I see this:
Started by user Me
Revision: 53eb41e0c05fd4cb466268947102990b2b14354e
GroovyImplementation
Revision: 825d8201904b000f479ebc91c9d244cfb956dd85
refs/remotes/origin/releases/release-2.18
On the "Changes" page I see changes for "GroovyImplementation" (of which there are frequently none) but I want changes for "refs/remotes/origin/releases/release-2.18" which is where the meaningful changes are.
Similarly, on the Stage View I see the number of commits for "GroovyImplementation" rather than the release branch.
How can I display checkout information for the release branch without using a multi-pipeline build?
Since you're using the branch selectedBranch - what you want is supposed to be supported out of the box by SCM step plugin (changelog by default is set to true).
However, I found it not working as well, so what you can do, is use the extension for this plugin: [$class: 'ChangelogToBranch', options: [compareRemote: 'myURL', compareTarget: "${selectedBranch}"]]
As you can see, extensions: gets an array of arrays, so you just add this extension to your existing, e.g.
extensions:
[
[$class: 'CloneOption', noTags: false, reference: "${cloneReference}", shallow: true, timeout: 5],
[$class: 'ChangelogToBranch', options: [compareRemote: 'myURL', compareTarget: "${selectedBranch}"]]
],
The changelog is calculated by default against a previous build, you can read it here https://github.com/jenkinsci/git-plugin#changelog-extensions. If you want the changelog to be calculated against a specific branch you can configure your job explicitly by adding additional behavior Calculate changelog against a specific branch
I have a Java project in http://localhost:7990/scm/bout/boutique-a.git
I want to have 2 Jenkins pipeline jobs:
Job 1/ trigger on commit done on */develop
Job 2/ trigger on commit done on any */feature
p
each job will do a basic mvn install, mvn test, sonar ...
a simple script with
node {
checkout([$class: 'GitSCM',
branches: [[name: 'develop]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption', disableSubmodules: false,
parentCredentials: false, recursiveSubmodules: true, reference: '',
trackingSubmodules: false]], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'admin',
url: 'http://localhost:7990/scm/bout/boutique-a.git']]])
}
works if a commit is done in /develop or if I give explicitly the branch name like feature/test-a but how to configure a script for any feature/
It seems that what i'm asking is not possible using pipeline job.
I found a work arround for "feature/** ". I created a param BRANCH_NAME in the job, then the branch name is send by bitbucket when a push is made on "feature/** " through a basic POST request.
http://user:token#localhost:8081/jenkins/job/MY_JOB_NAME/buildWithParameters?token=U1C1yQo7x3&BRANCH_NAME=feature/branche-test
Looking for the setting that makes jenkins remove previously checked out code, and check out a fresh / latest version of the code before the build.
yes, that's possible. i generated the following step from the "Pipeline Syntax" link in the left nav of each of my pipeline jobs in jenkins. Sample step is "Checkout: General SCM", SCM is "Subversion" and from there you can select a "Check-out strategy" of "Always check out a fresh copy".
checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[credentialsId: '196ff1ff-c481-4d2e-922b-e32410f8ee13', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://mycompany.example.com/svn/MYREPO/crs/trunk']], workspaceUpdater: [$class: 'CheckoutUpdater']])
the key part is:
workspaceUpdater: [$class: 'CheckoutUpdater']
If you're not familiar with declaring how your jobs will build using a Jenkinsfile yet (pipeline functionality), check out https://jenkins.io/doc/book/pipeline/. Here's what that "Pipeline Syntax" link looks like in the nav:
I have a project that spins up EC2 instances as build slaves, the username is "ec2-user".
I am checking out a repository with submodules like this:
checkout([
$class: 'GitSCM',
branches: [[name: 'deadbeefdeadbeefcafebabe']],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]
], submoduleCfg: [],
userRemoteConfigs: [
[credentialsId: 'deadbeef-cafe-babe-cafe-babebeef1234',
refspec: 'refs/changes/12/34567/89',
url: 'ssh://user#host:29418/some/project']
]
])
Please note that the URL has a username.
Now, the .gitmodules file looks like this:
[submodule "path/in/project"]
path = path/in/project
url = ssh://host:29418/other/project
branch = somebranch
The submodule description does not have a username specified. When it is time for the submodule clone, the clone is denied with invalid credentials. Manually editing the .gitmodules file and adding the user# in front of the URL works, but this is a bad workaround at best. Changing the URL on disk and then calling checkout again does also not work.
How can I make Jenkins use the username it used in the parent checkout? If that is not possible, what is a workaround which does not involve changing the source repo?