How to start, in a Jenkinsfile, a multibranch job inside a Bitbucket folder?

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

How to start, in a Jenkinsfile, a multibranch job inside a Bitbucket folder?

Amedee Van Gasse
In a Jenkinsfile, to start a parameterized pipeline job from another job, I have this code snippet:

    build job: 'build-sharpen-branch', parameters: [
            [$class: 'StringParameterValue', name: 'BRANCHNAME', value: mergeBranchname]
    ]

This already works as expected, and it will start a job at URL `https://$JENKINS_URL/job/build-sharpen-branch/`.

Now I want to start a job, that is one branch of a multibranch project inside a Bitbucket folder. The URL of the job is `https://$JENKINS_URL/job/iText%207%20.NET/job/sharpen/job/feature%2FQA-10738/`.
* `iText%207%20.NET` is the name of the Bitbucket project.
* `sharpen` is the name of the Multibranch job.
* `feature%2FQA-10738` is the name of the branch, urlencoded.

I read the following Stack Overflow questions about starting a multibranch job NOT inside a folder:
* https://stackoverflow.com/questions/50909730/trigger-multibranch-job-from-another
* https://stackoverflow.com/questions/45010601/triggering-a-multibranch-pipeline-job-from-an-other-multibranch-pipeline
* https://stackoverflow.com/questions/37322143/how-to-trigger-multibranch-pipeline-jenkins-job-within-regular-pipeline-job

From the answers there, I gather that the syntax is `$JOB/$BRANCH` (where `$BRANCH` is URL-encoded to rename branches like `feature/foo` to `feature%2Ffoo`).

From https://stackoverflow.com/questions/41182186/jenkins-pipeline-with-folder-plugin-how-to-build-a-job-located-different-folder I gather that the syntax for a job inside a folder is `$FOLDER/$JOB`.

Combining the two, I conclude that the syntax for folder+job+branch is most likely `$FOLDER/$JOB/$BRANCH`.

So I tried with this code:

    build job: "iText%207%20.NET/sharpen/${java.net.URLEncoder.encode branchName, 'UTF-8'}"

with

* folder = `iText%207%20.NET`
* job = `sharpen`
* branch = `${java.net.URLEncoder.encode branchName, 'UTF-8'}` *(URLEncoder to change `/` in the branch name to `%2F`)*

To my surprise, when I ran this, I got an error:

> ERROR: No item named iText%207%20.NET/sharpen/feature%2FQA-10738 found

As already stated above, a job exists on URL `https://$JENKINS_URL/job/iText%207%20.NET/job/sharpen/job/feature%2FQA-10738/`.

What is the correct syntax for a multibranch job inside a Bitbucket folder?

--
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/cd092530-9717-4ca1-927a-04fa92c0284cn%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to start, in a Jenkinsfile, a multibranch job inside a Bitbucket folder?

Amedee Van Gasse
The problem was with the folder name `iText%207%20.NET`, which is an urlencoded version of `iText 7 .NET`. Apparently Jenkins can't handle urlencoded spaces in folder names.

I renamed the folder to `itext_7_dotnet` and then used

    build job: "itext_7_dotnet/sharpen/${java.net.URLEncoder.encode branchName, 'UTF-8'}"

This works.


Moral of the story: never use spaces in your folder names!

On Tuesday, September 1, 2020 at 8:28:42 AM UTC+2 Amedee Van Gasse wrote:
In a Jenkinsfile, to start a parameterized pipeline job from another job, I have this code snippet:

    build job: 'build-sharpen-branch', parameters: [
            [$class: 'StringParameterValue', name: 'BRANCHNAME', value: mergeBranchname]
    ]

This already works as expected, and it will start a job at URL `https://$JENKINS_URL/job/build-sharpen-branch/`.

Now I want to start a job, that is one branch of a multibranch project inside a Bitbucket folder. The URL of the job is `https://$JENKINS_URL/job/iText%207%20.NET/job/sharpen/job/feature%2FQA-10738/`.
* `iText%207%20.NET` is the name of the Bitbucket project.
* `sharpen` is the name of the Multibranch job.
* `feature%2FQA-10738` is the name of the branch, urlencoded.

I read the following Stack Overflow questions about starting a multibranch job NOT inside a folder:

From the answers there, I gather that the syntax is `$JOB/$BRANCH` (where `$BRANCH` is URL-encoded to rename branches like `feature/foo` to `feature%2Ffoo`).


Combining the two, I conclude that the syntax for folder+job+branch is most likely `$FOLDER/$JOB/$BRANCH`.

So I tried with this code:

    build job: "iText%207%20.NET/sharpen/${java.net.URLEncoder.encode branchName, 'UTF-8'}"

with

* folder = `iText%207%20.NET`
* job = `sharpen`
* branch = `${java.net.URLEncoder.encode branchName, 'UTF-8'}` *(URLEncoder to change `/` in the branch name to `%2F`)*

To my surprise, when I ran this, I got an error:

> ERROR: No item named iText%207%20.NET/sharpen/feature%2FQA-10738 found

As already stated above, a job exists on URL `https://$JENKINS_URL/job/iText%207%20.NET/job/sharpen/job/feature%2FQA-10738/`.

What is the correct syntax for a multibranch job inside a Bitbucket folder?

--
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/aedeb36d-caa9-4368-8638-6a528fce551fn%40googlegroups.com.