SharedLibrary doesn´t allow git parameter to fetch all branches

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SharedLibrary doesn´t allow git parameter to fetch all branches

judaondo
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?


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/cf90e6c8-6bfe-44d4-a280-278f3719dab5%40googlegroups.com.

shared_lib_error.jpg (61K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SharedLibrary doesn´t allow git parameter to fetch all branches

Ganesan Srinivasan
Check this link https://plugins.jenkins.io/git-parameter/

Git parameter doesnt know from which repo(shared repo or project repo), it fetches the branch from shared repo. Follow the below steps to solve this issue

If in the task are defined multiple repositories, this option specifies which the repository is taken into account on getting data.
If the option is not defined, is taken a first defined repository.
This option is a regular expression, which is compared to the 'Repository URL'.

You can define the multiple SCM for few way, you can use Multiple SCMs Plugin, specified many 'Repository URL' in one SCM  or define them in pipeline.

Consider an example based on two repositories:


Pipeline: Complex example
pipeline {
    agent any
    parameters {
        gitParameter branchFilter: 'origin.*/(.*)', defaultValue: 'master', name: 'BRANCH_A', type: 'PT_BRANCH', useRepository: '.*exampleA.git'
        gitParameter branchFilter: 'origin.*/(.*)', defaultValue: 'master', name: 'BRANCH_B', type: 'PT_BRANCH', useRepository: '.*exampleB.git'
        
    }
    stages {
        stage('Example') {
            steps {
                git branch: "${params.BRANCH_A}", url: 'https://github.com/klimas7/exampleA.git'
                git branch: "${params.BRANCH_B}", url: 'https://github.com/klimas7/exampleB.git'
            }
        }
    }
}
Hope this solves the issue


On Tuesday, 11 February 2020 05:28:27 UTC+13, judaondo wrote:
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: '<a href="http://gitserver:8080/myproject" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgitserver%3A8080%2Fmyproject\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFQQQ9TZr3y_S_apN18L-esh0IJ5w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgitserver%3A8080%2Fmyproject\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFQQQ9TZr3y_S_apN18L-esh0IJ5w&#39;;return true;">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 (<a href="https://plugins.jenkins.io/git-parameter/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fplugins.jenkins.io%2Fgit-parameter%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGL7Zh-rKIGeTA5KDAuXqwXjgfXEQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fplugins.jenkins.io%2Fgit-parameter%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGL7Zh-rKIGeTA5KDAuXqwXjgfXEQ&#39;;return true;">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?


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e5477f39-b367-4faa-b2d1-69b47053126do%40googlegroups.com.