Skip to content

repositoryUrl with .git extension causes authentication failure in Multi-branch Pipelines #2549

@mjgit007

Description

@mjgit007

Jenkins and plugins versions report

When defining a Multi-branch Pipeline using Job DSL, the repositoryUrl field for GitHub SCMSources is documented to support URLs both with and without the .git extension. This is related to the issue jenkinsci/configuration-as-code-plugin#2753

Image

GitHub examples:
https://github.com/jenkinsci/github-branch-source-plugin
https://github.com/jenkinsci/github-branch-source-plugin.git

However, when a job is generated using a URL ending in .git, the initial repository scan fails with authentication/credential errors (e.g., FATAL: Invalid scan credentials).

Manual intervention in the Jenkins UI specifically clicking "Configure" and then "Save" without making changes resolves the issue until the next JCasC/Job DSL synchronisation.

What Operating System are you using (both controller, and any agents involved in the problem)?

Controller is running as a Docker container in AKS cluster. Created jenkins controller using https://github.com/jenkinsci/helm-charts

Reproduction steps

Steps to Reproduce
Create a Multi-branch Pipeline using Job DSL (via JCasC ).

controller:  
  JCasC:
    configScripts:
      jobs: |
        jobs:
          - script: folder('Applications')
          - script: folder('Applications/frontend')
          - script: >
              multibranchPipelineJob('Applications/frontend/digital-web') {
                displayName('digital-web')
                branchSources {
                  branchSource {
                    buildStrategies {
                     skipInitialBuildOnFirstBranchIndexing()
                    }
                    source {
                      github {
                        id('100000')
                        credentialsId('github-pat')
                        configuredByUrl(true)
                        repoOwner('test')
                        repositoryUrl('https://github.com/test')
                        repository('digital-web.git')
                        traits {
                          gitHubPullRequestDiscovery { strategyId(1) } 
                          gitHubIgnoreDraftPullRequestFilter()
                        }
                      }
                    }
                  }
                }
                factory { workflowBranchProjectFactory { scriptPath('.jenkins/Jenkinsfile') } }
                orphanedItemStrategy { discardOldItems { numToKeep(20) } }
              }

Set the repositoryUrl to include the .git suffix (e.g., https://github.com/user/repo.git).

Observe the job fails to scan the repository, reporting invalid credentials.

Update the DSL to remove the .git suffix (e.g., https://github.com/user/repo).

Observe the job scans successfully.

Expected Results

The Job DSL plugin should handle the .git extension as specified in the API documentation, ensuring that the generated XML correctly initialises the GitHub SCM source.

Actual Results

Including .git in the repositoryUrl leads to a configuration state that Jenkins cannot use for authentication until the job is manually saved through the UI.

Anything else?

No response

Are you interested in contributing a fix?

Proposed Fix
Short Term: Update the Job DSL documentation to clarify that .git should be omitted for GitHub SCMSources.

Long Term: Update the plugin logic to automatically sanitise or properly parse the repositoryUrl even when the .git extension is present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions