SharedLibrary doesn´t allow git parameter to fetch all branches

48 views
Skip to first unread message

judaondo

unread,
Feb 21, 2020, 3:53:56 AM2/21/20
to Jenkins Users
Hello, 

I have the following pipeline that uses a method called "getServiceVersion" from a Shared Library.


#!/usr/bin/env groovy

@Library('mycom')

import com.mycom.*


// Declarative pipeline //

properties
([[$class: 'JiraProjectProperty'], buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')), disableConcurrentBuilds(), parameters([gitParameter(branch: '', branchFilter: '.*', defaultValue: 'origin/integration', description: 'Git Branch', listSize: '10', name: 'branch', quickFilterEnabled: true, selectedValue: 'DEFAULT', sortMode: 'ASCENDING_SMART', tagFilter: '*', type: 'PT_BRANCH')])])

def STAGE

pipeline 
{
    agent 
{ label 'WindowsSlaveWS2016' }

    options 
{
        timestamps 
()
        ansiColor
('xterm')
        disableConcurrentBuilds
()
    
}

    stages 
{
        stage
('Code checkout') {
            steps 
{
                echo 
'<< Checking out source code >>'
                checkout
([$class: 'GitSCM', branches: [[name: '${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 10, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitcredentials', url: 'http://gitserver:8080/myproject']]])
                script 
{
                    STAGE
=env.STAGE_NAME
                
}
            
}
        
}
        stage
('Get service version') {
            steps 
{
                script 
{
                    STAGE
=env.STAGE_NAME
                    getServiceVersion
('MY/Path', 'ChangeLog.txt', 'myservice')
                
}
            
}
        
}
       
    
}

}


Please notice at the 'git parameter (https://plugins.jenkins.io/git-parameter/)' that fetchs all available branches on the current repository and the selected default vale 'origin/integration'. 

Since I am using shared library it doesn´t load all the available branches and in fact it only displays origin/master instead of origin/integration.

There is a kind of incompatibility? How can I fix this behaviour?

shared_lib_error.jpg


judaondo

unread,
Feb 21, 2020, 3:54:35 AM2/21/20
to Jenkins Users
shared_lib_error.jpg

Mark Waite

unread,
Feb 21, 2020, 9:09:44 AM2/21/20
to Jenkins Users
I'd call it a misunderstanding more than an incompatibility.  The git parameter is providing a filter which can limit the set of branches which might be included.  The git parameter cannot expand the set of branches which might be included.  The multibranch pipeline job definition controls the initial set of branches being requested into the workspace.  The branch you're seeking is not being brought into the workspace.

Branch sources that use the REST API to detect changes (GitHub, Bitbucket, Gitea, GitLab) are intentionally optimized to only populate the workspace with the commits for the exact branch being built.  That can save significant time and space with large repositories that contain multiple branches.  If you require more history than the exact branch being built, then you'll likely need to adjust the checkout that you're using to populate the workspace.

I'm not clear why you're using a branch parameter in a Pipeline job.  Isn't it more effective to define a Jenkinsfile in each branch and then allow the multibranch pipeline to create and destroy jobs automatically as branches are created and destroyed?

Mark Waite

judaondo

unread,
Mar 3, 2020, 10:40:58 AM3/3/20
to Jenkins Users
Hello Mark,

I need to clone 2 repositories, so I can´t place the Jenkinsfile in one repository or another.

I need to place the code directly in the Jenkinsfile inside the job. 

The thing is that branches are not loaded in the git paramater.

Is there any workaround to fix this?

Thank you.

Mark Waite

unread,
Mar 3, 2020, 10:44:25 AM3/3/20
to Jenkins Users
If you need to clone two repositories and can't get the branch names from a git parameter, you could use a string parameter and list the choice of branches yourself.  Or, you could experiment with the git parameter plugin to see if you can find a way to resolve the issue that you're seeing.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/649378a4-fc37-4d17-ab7a-5916996a629f%40googlegroups.com.

judaondo

unread,
Mar 3, 2020, 11:05:17 AM3/3/20
to Jenkins Users
Yes, finally I used "String parameter" but that was, what I was trying to avoid... I wanted to help anyone selecting their branch and not typing it.

Thank you for your support :)

vince bailey

unread,
Mar 3, 2020, 11:10:33 AM3/3/20
to 'Björn Pedersen' via Jenkins Users
Have you installed the multibranch and multipipeline plugins that will help.

The other thing is were you want to set the git repo information in jenkins cred’s jenkins golbal or in the jenkinsfile
don’t mix and match

-- 
Regards,

Vince Bailey

Live long and prosper !!!



On 3 Mar 2020, at 16:05, judaondo <jonu...@gmail.com> wrote:

Yes, finally I used "String parameter" but that was, what I was trying to avoid... I wanted to help anyone selecting their branch and not typing it.

Thank you for your support :)

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

judaondo

unread,
Mar 3, 2020, 2:49:38 PM3/3/20
to Jenkins Users
Which plugins are those? 


and multipipeline plugin?

Thank you.
Reply all
Reply to author
Forward
0 new messages