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

Use core.autocrlf true for Windows line termination #899

Merged
merged 3 commits into from
Jan 11, 2025

Conversation

MarkEWaite
Copy link
Contributor

@MarkEWaite MarkEWaite commented Jan 10, 2025

Use LF as git end of line terminator on Windows

Windows virtual machines are currently configured to not use LF as their git end of line. That causes failures when spotless formats files on Windows that were originally created with Unix (LF) line termination.

This is a workaround until we update the Windows virtual machine definition to fix:

Testing done

I added the following text to the start of each Jenkinsfile in the test jobs and confirmed that job output contained the expected git commands on Windows agents and the test jobs passed with both useContainerAgent: true and useContainerAgent: false.

@Library('pipeline-library@set-autocrlf-on-windows') _

Plugins that were tested with both settings include:

  • Built-on Column plugin PR-53 and master branch builds 63 and 64 - uses spotless
  • Apache httpclient 4 API plugin builds 202 and 203 - uses spotless
  • GitHub branch source plugin builds 484 and 485 - uses spotless
  • JUnit plugin builds 443 and 444 - uses spotless
  • Pipeline input step plugin builds 70 and 71 - does not use spotless
  • Pipeline SCM step plugin builds 74 and 75 -does not use spotless
  • Bitbucket branch source plugin 547 and 548 - does not use spotless

Plugins that were tested with only one setting (because they require a virtual machine to run their container based tests):

  • SSH build agents plugin build 77 - does not use spotless
  • Git client plugin build 1213 - uses spotless

Windows virtual machines are currently configured to not use LF as their
git end of line.  That causes failures when spotless formats files on
Windows that were originally created with Unix (LF) line termination.

This is a workaround until we update the Windows virtual machine
definition to fix:

* jenkins-infra/helpdesk#3865
@MarkEWaite MarkEWaite requested a review from a team as a code owner January 10, 2025 17:04
Copy link
Contributor

@lemeurherveCB lemeurherveCB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned elsewhere, this PR should go along #898 as

plugins that use spotless will fail their builds on a Windows VM when they pass on a Windows container. Switch from container to VM makes that issue visible to more people.

Related:

Copy link

@gounthar gounthar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Mark!

@MarkEWaite
Copy link
Contributor Author

@lemeurherveCB suggested a technique that I can use to test this before it is merged. I'll do that testing before I merge it.

jonesbusy
jonesbusy previously approved these changes Jan 10, 2025
@jglick
Copy link
Contributor

jglick commented Jan 10, 2025

CC @jtnord

@@ -142,6 +142,8 @@ Object checkoutSCM(String repo = null) {
// Enable long paths to avoid problems with tests on Windows agents
if (!isUnix()) {
bat 'git config --global core.longpaths true'
// TODO: Remove when https://github.com/jenkins-infra/helpdesk/issues/3865 is resolved
bat 'git config --global core.eol lf'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the spotless issue is that it ends up just guessing that the line ending is native becasue there is no configuration otherwise.

The alternative (which uses windows line ends on windows, so is more like what windows would do) is to set git config --global core.autocrlf true

this should cause the files to have line ends changed on windows, and will be picked up by spotless to go "oh it is converting line ends, and I am on windows" so spotless does not end up guessing.

Copy link
Contributor Author

@MarkEWaite MarkEWaite Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very, very much! Your guidance was exactly what I needed. I confirmed that core.autocrlf true resolves the spotless formatting issue and allows builds to be portable between ci.jenkins.io Windows containers and Windows virtual machines Setting core.eol lf does not resolve the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timja timja merged commit 59f16e6 into jenkins-infra:master Jan 11, 2025
3 checks passed
@MarkEWaite MarkEWaite deleted the force-lf-eol-on-windows branch January 13, 2025 14:36
@MarkEWaite MarkEWaite changed the title Use LF as git end of line terminator on Windows Use core.autocrlf true for Windows line termination Jan 13, 2025
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

Successfully merging this pull request may close these issues.

8 participants