Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: Branch Restriction not working with 2 or more branch names #388

Open
kabua opened this issue Mar 11, 2024 · 10 comments
Open

Comments

@kabua
Copy link

kabua commented Mar 11, 2024

Configuration:

  • Windows Server 2019
  • Jenkins 2.440.1
  • GitHub Integration Plugin 0.7.0

After a lot of work, we finally got this plugin working. Except when trying to whitelist two or more branches under the Experimental: Branch Restriction > Whitelist Target Restrictions section.

We have the following top-level protected branches: DEV, RELEASE, PROD, and HOTFIX.

In my test repo, I have PR from Features/100-testing merging into DEV.

If I set the WhiteList to DEV it works. If I set it to ABC, it fails - as expected.

BUT, if I try and use a multi-line, like so:
image

It fails, with this log entry:
image

Before searching the source code, I also tried using semi-colons (:), commas (,), and spaces ( ), which also failed.

I don't understand why Java's System.lineSeparator() doesn't recognize Jenkin's line separator.

public class GitHubPRBranchRestriction implements Describable<GitHubPRBranchRestriction> {
    private static final String LINE_SEPARATOR = System.lineSeparator();

Source file.

@KostyaSha
Copy link
Owner

what is written into xml config?

@KostyaSha
Copy link
Owner

KostyaSha commented Mar 11, 2024

According to code each line is used for Pattern compilation. You can try to put your rule into single line regexp.

@kabua
Copy link
Author

kabua commented Mar 11, 2024

@KostyaSha thanks for the quick reply.

what is written into xml config?

Where would I find this XML config file?

@kabua
Copy link
Author

kabua commented Mar 11, 2024

Using DEV|RELEASE worked!

@KostyaSha, thank you.

@KostyaSha
Copy link
Owner

Where would I find this XML config file?

on jenkins master in job's folder

@kabua
Copy link
Author

kabua commented Mar 11, 2024

We think we know what the bug is...

The log file shows this:

<branchRestriction>
        <targetBranchList>
          <string>DEV
RELEASE</string>
        </targetBranchList>

Using Note++, we verified that the file's line format is Unix (LF). But on Windows, we think that Java is returning \r\n thus.

private static List<String> split(String targetBranch) {
        return Arrays.asList(targetBranch.trim().split(LINE_SEPARATOR));
    }

can't split on \r\n because it only find \n.

Thus, LINE_SEPARATOR should be hard-coded to \n or split first on \r\n and then on \n.

@kabua
Copy link
Author

kabua commented Mar 11, 2024

To verify this idea, we converted the file to Windows (CR LF), then restarted the Jenkins service and tested again. But it still failed. 🤔

At least the regex idea works. 😃

@KostyaSha
Copy link
Owner

KostyaSha commented Mar 11, 2024

To verify this idea, we converted the file to Windows (CR LF), then restarted the Jenkins service and tested again. But it still failed. 🤔

the correct order may be shutdown, modify, start and verify. On shutdown it may save configs with in-memory data

@kabua
Copy link
Author

kabua commented Mar 13, 2024

It was a good idea, but it didn't work.

@KostyaSha - as it appears that this can't be fixed, should we close it out?

@kabua
Copy link
Author

kabua commented Mar 13, 2024

For those who also ran into this issue...

To recap the solution, the only viable way to whitelist multiple branches on a Windows machine is to use JAVA'S regex, like so:

DEV|MASTER|HOTFIX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants