Jx: Error when parsing Git URL on Bitbucket Server

Created on 27 Feb 2020  路  7Comments  路  Source: jenkins-x/jx

Summary

Some commands like jx import or jx create devpod need to clone a Git repo in order to work.
If you use Bitbucket Server, this repo URL isn't parsed correctly in this step.

In the Bitbucket web interface, the clone URL is something like https://git.***.fr/scm/<PROJECT>/<REPO>.git.
These commands are failing because they don't have the right clone URL (it is missing the /scm part) : fatal: repository 'https://git.***.fr/<PROJECT>/<REPO>.git/' not found.

I think it is related to this line in the code : https://github.com/jenkins-x/jx/blob/1976d34ff6ac7df0c8874c9f99c32586e6f3b524/pkg/gits/git_url.go#L203-L204

Steps to reproduce the behavior

I tested these cases : install Jenkins X with Bitbucket Server and either :

  • run jx create devpod
  • run jx import with webhook: lighthouse

Expected behavior

The repository is correctly cloned.

Actual behavior

It fails with an error like

Cloning into '<REPO>'...
fatal: repository 'https://git.***.fr/<PROJECT>/<REPO>.git/' not found
command terminated with exit code 128

Jx version

The output of jx version is:

NAME               VERSION
jx                 2.0.1202
Kubernetes cluster v1.17.2
kubectl            v1.16.0
helm client        Client: v2.16.3+g1ee0254
git                2.17.1
Operating System   Ubuntu 18.04.4 LTS

Jenkins type

  • [x] Serverless Jenkins X Pipelines (Tekton + Prow)
  • [ ] Classic Jenkins

Kubernetes cluster


On premise

Operating system / Environment

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic
arebitbucket kinbug prioritimportant-longterm

Most helpful comment

I'm hoping #7173 deals with this, but I'm going to test it against BitBucket Server tomorrow. The challenge is that we can generate the GitRepository in a few different ways, so HttpCloneURL() doesn't necessarily know what the underlying server is.

All 7 comments

So I believe that the problem is not that we're trimming /scm in parsePath, it's that we're not putting it back when getting the clone URL from the SourceRepository (and possibly other places).

Still reproducible on jx version 2.0.1240. Interestingly enough I tried jx import of an existing
maven project and it failed but it worked with a react project one of my colleagues imported/created.

Hello, I retried today with the jx version 2.0.1258 and the command jx create quickstart with the php-helloworld template.

It is working with Traditional Jenkins (webhook: jenkins in jx-requirements) but it fails if I use LightHouse (webhook: lighthouse in jx-requirements).

If it could help, here is an error that is shown in the command jx get build logs <PROJECT>/<REPO>/master :

{"level":"error","ts":1585643585.0040672,"logger":"fallback-logger","caller":"git/git.go:40","msg":"Error running git [fetch --depth=1 --recurse-submodules=yes origin master]: exit status 128\nfatal: repository 'https://git.***.fr/<PROJECT>/<REPO>.git/' not found\n","stacktrace":"github.com/tektoncd/pipeline/pkg/git.run\n\t/Users/abayer/go/src/github.com/tektoncd/pipeline/pkg/git/git.go:40\ngithub.com/tektoncd/pipeline/pkg/git.Fetch\n\t/Users/abayer/go/src/github.com/tektoncd/pipeline/pkg/git/git.go:91\nmain.main\n\t/Users/abayer/go/src/github.com/tektoncd/pipeline/cmd/git-init/main.go:39\nruntime.main\n\t/usr/local/Cellar/go/1.12.4/libexec/src/runtime/proc.go:200"}

Just tried this with 2.1.31 and it's still failing. Getting the sourcerepository resource, cloneUrl is still missing scm. Tried this with jx create quickstart and jx import a local folder

I found some functions in the code that could be related to this issue.

https://github.com/jenkins-x/jx/blob/22ce2138110e61c4497f02efc8205dd2fc8de718/pkg/gits/git_url.go#L28-L31

calls this function

https://github.com/jenkins-x/jx/blob/22ce2138110e61c4497f02efc8205dd2fc8de718/pkg/gits/git_url.go#L42-L49

but it doesn't add the /scm between the host and the organisation.

Nicely spotted @AntoineFr, meanwhile I am using a bit of kubectl and scripting to workaround it

kubectl get sourcerepositories.jenkins.io ${PROJECT_NAME}-${REPO_NAME} -o yaml > ${PROJECT_NAME}-${REPO_NAME}.yaml
INPUT_STRING="httpCloneURL: ${BITBUCKET_SERVER}/${PROJECT_NAME}/"
FIX_STRING="httpCloneURL: ${BITBUCKET_SERVER}/scm/${PROJECT_NAME}/"
sed -i "s|${INPUT_STRING}|${FIX_STRING}|g" ${PROJECT_NAME}-${REPO_NAME}.yaml
kubectl apply -f ${PROJECT_NAME}-${REPO_NAME}.yaml

Edit: although I have to say that the first meta-pipeline will fail anyway because it will start before I can possibly update that resource.

In fact it fails while upserting the Pipeline resource and a bit of digging brought me here:

https://github.com/jenkins-x/jx/blob/a0d4c5a2b5d536ea39354ded26226474c8fb4765/pkg/tekton/pipelines.go#L433-L438

I'm hoping #7173 deals with this, but I'm going to test it against BitBucket Server tomorrow. The challenge is that we can generate the GitRepository in a few different ways, so HttpCloneURL() doesn't necessarily know what the underlying server is.

Was this page helpful?
0 / 5 - 0 ratings