jenkins pipelineのgithub アクセストークン対応

githubからちょくちょく対応しろよメールがきてました。僕は対応済みだよガハハとイキってました。

Could not checkout develop with start point

対応できてませんでした…

jenkinsでアクセストークン使う

Attention Required! | Cloudflare

お馴染みのパスワードとして使えるようです

  • Go to credentials > System > Global credentials > Add credentials a page will open.
  • In Kind drop-down select Username and password.
  • In User put a non-existing username like jenkins-user or user.(
  • Add Personal Access Token in the password field

パスワードのところにアクセストークンを張り付けましょう

jenkins scriptでのgit関数のurl引数の表記を変える

git@github.com:masak2/{repository}.git

以前はこれでした

ERROR: Error fetching remote repo 'origin'

hudson.plugins.git.GitException: Failed to fetch from git@github.com:masak2/{repository}.git

	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1000)

	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1241)

	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1301)

	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)

	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)

	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)

	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)

	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

	at java.util.concurrent.FutureTask.run(Unknown Source)

	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.lang.Thread.run(Unknown Source)

Caused by: hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe fetch --tags --force --progress -- git@github.com:masak2/{repository}.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:

stdout: 

stderr: git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.


Please make sure you have the correct access rights

and the repository exists.


	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2661)

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2086)

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:86)

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:608)

	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:998)

	... 11 more

Error fetching remote repo 'origin'

エラーが噴出します

https://github.com/masak2/{repository}.git

これに変えたら正常に動作しました。