Building a Github project fails irregularly

Hi, our organisation is moving from on-site hosted SVN for our source control to using GitHub. I’ve been looking into how to pull from the GH repo and do a build in Jenkins, as we previously did with SVN. I’ve followed the steps from Authenticating with GitHub on Jenkins CI using a GitHub App and had our infrastructure people create a GH App for me. They gave me the app ID and private key. I installed that as a credential in Jenkins, created a new project using GH for SCM and pointed it at my repo. I haven’t even tried testing the webhook yet to see if it will build on changes, but have just been triggering builds manually. And it works. Sometimes.

Sometimes, it works as expected and the start of the output looks like this:

Started by user [me]
Running as SYSTEM
Building on the built-in node in workspace path\to\workspace
The recommended git tool is: NONE
using credential [redacted]
 > git.exe rev-parse --resolve-git-dir path\to\workspace\.git # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/myorg/myrepo.git # timeout=10
Fetching upstream changes from https://github.com/myorg/myrepo.git
 > git.exe --version # timeout=10
 > git --version # 'git version 2.50.0.windows.2'
using GIT_ASKPASS to set credentials Campus Resources Github access
Setting http proxy: server:port
 > git.exe fetch --tags --force --progress -- https://github.com/myorg/myrepo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git.exe rev-parse "refs/remotes/origin/main^{commit}" # timeout=10
Checking out Revision [redacted] (refs/remotes/origin/main)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f [redacted] # timeout=10
Commit message: "Adding .gitignore"
 > git.exe rev-list --no-walk [redacted] # timeout=10
[workspace] $ cmd.exe /C "path\to\maven\bin\mvn.cmd -Ddependency.locations.enabled=false clean install && exit %%ERRORLEVEL%%"
[INFO] Scanning for projects...
[INFO] 
... etc

But sometimes, it just fails with this:

Started by user [me]
Running as SYSTEM
Building on the built-in node in workspace path\to\workspace
The recommended git tool is: NONE
using credential [redacted]
 > git.exe rev-parse --resolve-git-dir path\to\workspace\.git # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/myorg/myrepo.git # timeout=10
Fetching upstream changes from https://github.com/myorg/myrepo.git
 > git.exe --version # timeout=10
 > git --version # 'git version 2.50.0.windows.2'
using GIT_ASKPASS to set credentials Campus Resources Github access
Setting http proxy: server:port
 > git.exe fetch --tags --force --progress -- https://github.com/myorg/myrepo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/myorg/myrepo.git
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:998)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1239)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1310)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1277)
	at hudson.scm.SCM.checkout(SCM.java:540)
	at hudson.model.AbstractProject.checkout(AbstractProject.java:1250)
	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649)
	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522)
	at hudson.model.Run.execute(Run.java:1842)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:456)
Caused by: hudson.plugins.git.GitException: Command "git.exe fetch --tags --force --progress -- https://github.com/myorg/myrepo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/myorg/myrepo.git/'

	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2844)
	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2189)
	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:638)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:996)
	... 12 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

The server is a Windows Server 2019 and exists on private address space on our network, not exposed to the wider internet. I’ve set a proxy in git using:

git config --global http.proxy http://proxyserver:port

Any help would be appreciated.

Jenkins setup:

Jenkins: 2.540
OS: Windows Server 2019 - 10.0
Java: 21.0.3 - Amazon.com Inc. (OpenJDK 64-Bit Server VM)
---
ansicolor:1.0.6
ant:520.vd082ecfb_16a_9
antisamy-markup-formatter:173.v680e3a_b_69ff3
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
artifactdeployer:1.3
asm-api:9.9-185.va_6c6b_3348b_c3
authentication-tokens:1.144.v5ff4a_5ec5c33
bootstrap5-api:5.3.8-895.v4d0d8e47fea_d
bouncycastle-api:2.30.1.82-277.v70ca_0b_877184
branch-api:2.1268.v044a_87612da_8
caffeine-api:3.2.3-194.v31a_b_f7a_b_5a_81
checks-api:373.vfe7645102093
cloudbees-folder:6.1073.va_7888eb_dd514
command-launcher:123.v37cfdc92ef67
commons-collections4-api:4.5.0-8.va_d5448ef9011
commons-lang3-api:3.19.0-104.v12125f33a_255
commons-text-api:1.14.0-194.v804a_dc3a_1b_d8
conditional-buildstep:1.5.0
config-file-provider:1006.vc7366c201f57
coverage:2.3054.ve1ff7b_a_a_123b_
credentials:1453.v9b_a_29777a_b_fd
credentials-binding:702.vfe613e537e88
cvs:483.v69a_98dfd973b_
data-tables-api:2.3.5-1482.vb_47a_3c19f78c
dependency-check-jenkins-plugin:5.6.2
display-url-api:2.217.va_6b_de84cc74b_
docker-commons:457.v0f62a_94f11a_3
docker-workflow:634.vedc7242b_eda_7
durable-task:639.vefb_3d8372f6d
echarts-api:6.0.0-1165.vd1283a_3e37d4
eddsa-api:0.3.0.1-19.vc432d923e5ee
extended-read-permission:68.vd270568a_7520
external-monitor-job:223.vb_fddcf42c9b_3
font-awesome-api:7.1.0-882.v1dfb_771e3278
forensics-api:3.1772.v99ca_3d83b_9fa_
git:5.8.1
git-client:6.4.0
git-server:137.ve0060b_432302
github:1.45.0
github-api:1.330-492.v3941a_032db_2a_
github-branch-source:1925.v62fb_7ffb_08ce
github-pullrequest:0.7.2
gson-api:2.13.2-173.va_a_092315913c
htmlpublisher:427
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
jackson2-api:2.20.1-423.v13951f6b_6532
jakarta-activation-api:2.1.4-1
jakarta-mail-api:2.1.5-1
jakarta-xml-bind-api:4.0.6-10.v9b_7e1d1fc40b_
javadoc:354.vee1a_660b_4990
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-133.vb_ec76a_73f706
jdk-tool:83.v417146707a_3d
jersey2-api:2.47-165.ve7809a_3e87e0
jira:3.20
jjwt-api:0.11.5-120.v0268cf544b_89
joda-time-api:2.14.0-149.v1c3ce991d1b_9
jquery:1.12.4-3
jquery3-api:3.7.1-619.vdb_10e002501a_
jsch:0.2.16-95.v3eecb_55fa_b_78
json-api:20250517-173.v596efb_962a_31
json-path-api:2.10.0-202.va_9cc16c1e476
jsoup:1.21.2-66.v6ea_38164b_8a_2
junit:1380.v491ff054cd35
ldap:793.v754d6b_41b_ea_4
lockable-resources:1438.v3c0f8c9e2060
mailer:525.v2458b_d8a_1a_71
mapdb-api:1.0.9-44.va_1e1310c9118
matrix-auth:3.2.9
matrix-project:870.v9db_fcfc2f45b_
maven-plugin:3.27
mina-sshd-api-common:2.16.0-167.va_269f38cc024
mina-sshd-api-core:2.16.0-167.va_269f38cc024
nodejs:1.6.6
okhttp-api:4.12.0-195.vc02552c04ffd
oss-symbols-api:424.ved751e062911
pam-auth:1.12
pipeline-build-step:571.v08a_fffd4b_0ce
pipeline-graph-analysis:245.v88f03631a_b_21
pipeline-groovy-lib:787.ve2fef0efdca_6
pipeline-input-step:540.v14b_100d754dd
pipeline-milestone-step:138.v78ca_76831a_43
pipeline-model-api:2.2277.v00573e73ddf1
pipeline-model-definition:2.2277.v00573e73ddf1
pipeline-model-extensions:2.2277.v00573e73ddf1
pipeline-rest-api:2.38
pipeline-stage-step:322.vecffa_99f371c
pipeline-stage-tags-metadata:2.2277.v00573e73ddf1
pipeline-stage-view:2.38
plain-credentials:199.v9f8e1f741799
plugin-util-api:6.1192.v30fe6e2837ff
prism-api:1.30.0-630.va_e19d17f83b_0
role-strategy:848.va_a_ea_673cf0b_c
run-condition:243.v3c3f94e46a_8b_
scm-api:724.v7d839074eb_5c
script-security:1385.v7d2d9ec4d909
snakeyaml-api:2.5-143.v93b_c004f89de
sonar:2.18.1
ssh-credentials:361.vb_f6760818e8c
ssh-slaves:3.1085.vc64d040efa_85
sshd:3.374.v19b_d59ce6610
structs:362.va_b_695ef4fdf9
subversion:1292.ve8cf25770ee3
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.284.v1974ea_324382
variant:70.va_d9f17f859e0
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1398.v67030756d3fb_
workflow-basic-steps:1098.v808b_fd7f8cf4
workflow-cps:4238.va_6fb_65c1f699
workflow-durable-task-step:1464.v2d3f5c68f84c
workflow-job:1559.va_a_533730b_ea_d
workflow-multibranch:821.vc3b_4ea_780798
workflow-scm-step:466.va_d69e602552b_
workflow-step-api:710.v3e456cc85233
workflow-support:1010.vb_b_39488a_9841

Hi folks, some more information here that may be of help:

If I go into my project > configure > source code management, and wait a few seconds, I’ll see this error appear:

Failed to connect to repository : Command “git.exe ls-remote -h – https://github.com/myOrganisation/myProject.git HEAD” returned status code 128:
stdout:
stderr: remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for ‘https://github.com/myOrganisation/myProject.git/

Credentials

But if then exit back to the project page, and then go back to the same screen, the error doesn’t appear, and I can build normally.

So something seems to be going on with authentication timing out, and then being refreshed. Can anyone help?