在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:jenkinsci/github-plugin开源软件地址:https://github.com/jenkinsci/github-plugin开源编程语言:Java 94.5%开源软件介绍:Github PluginThis plugin integrates Jenkins with Github projects.The plugin currently has three major functionalities:
Hyperlinks between changesThe Github plugin decorates Jenkins "Changes" pages to create links to your Github commit and issue pages. It adds a sidebar link that links back to the Github project page. When creating a job, specify that is connects to git. Under "Github project", put in: [email protected]:Person/Project.git Under "Source Code Management" select Git, and put in [email protected]:Person/Project.git GitHub hook trigger for GITScm pollingThis feature enables builds after post-receive hooks in your GitHub repositories. This trigger only kicks git-plugin internal polling algo for every incoming event against matched repo.
UsageTo be able to use this feature different mode are available :
Manual ModeIn this mode, you'll be responsible for registering the hook URLs to
GitHub. Click the
icon (under Manage Jenkins > Configure System > GitHub) to see the URL
in Jenkins that receives the post-commit POSTs — but in general the URL
is of the form Once you have the URL, and have added it as a webhook to the relevant GitHub repositories, continue to Step 3. Automatic Mode (Jenkins manages hooks for jobs by itself)In this mode, Jenkins will automatically add/remove hook URLs to GitHub based on the project configuration in the background. You'll specify GitHub OAuth token so that Jenkins can login as you to do this. Step 1. Go to the global configuration and add GitHub Server Config. Step 2.1. Create your personal access token in GitHub. Plugin can help you to do it with all required scopes. Go to Advanced -> Manage Additional GitHub Actions -> Convert Login and Password to token
Step 2.2. Select previously created "Secret Text" credentials with GitHub OAuth token. Required scopes for token To be able manage hooks your token should have admin:org_hook scope. GitHub Enterprise You can also redefine GitHub url by clicking on Custom GitHub API
URL checkbox. Step 3. Once that configuration is done, go to the project config of each job you want triggered automatically and simply check "GitHub hook trigger for GITScm polling" under "Build Triggers". With this, every new push to the repository automatically triggers a new build. Note that there's only one URL and it receives all post-receive POSTs for all your repositories. The server side of this URL is smart enough to figure out which projects need to be triggered, based on the submission. Security ImplicationsThis plugin requires that you have an HTTP URL reachable from GitHub, which means it's reachable from the whole internet. So it is implemented carefully with the possible malicious fake post-receive POSTS in mind. To cope with this, upon receiving a POST, Jenkins will talk to GitHub to ensure the push was actually made. Jenkins inside a firewallIn case your Jenkins run inside the firewall and not directly reachable from the internet, this plugin lets you specify an arbitrary endpoint URL as an override in the automatic mode. The plugin will assume that you've set up reverse proxy or some other means so that the POST from GitHub will be routed to the Jenkins. Trouble-shooting hooksIf you set this up but build aren't triggered, check the following things:
Using cache to GitHub requestsEach GitHub Server Config creates own GitHub client to interact with api. By default it uses cache (with 20MB limit) to speedup process of fetching data and reduce rate-limit consuming. You can change cache limit value in "Advanced" section of this config item. If you set 0, then this feature will be disabled for this (and only this) config. Additional info:
Possible Issues between Jenkins and GitHubWindows:
Pipeline examplesSetting commit statusThis code will set commit status for custom repo with configured context and message (you can also define same way backref) void setBuildStatus(String message, String state) {
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "https://github.com/my-org/my-repo"],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/build-status"],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}
setBuildStatus("Build complete", "SUCCESS"); More complex example (can be used with multiple scm sources in pipeline) def getRepoURL() {
sh "git config --get remote.origin.url > .git/remote-url"
return readFile(".git/remote-url").trim()
}
def getCommitSha() {
sh "git rev-parse HEAD > .git/current-commit"
return readFile(".git/current-commit").trim()
}
def updateGithubCommitStatus(build) {
// workaround https://issues.jenkins-ci.org/browse/JENKINS-38674
repoUrl = getRepoURL()
commitSha = getCommitSha()
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
errorHandlers: [[$class: 'ShallowAnyErrorHandler']],
statusResultSource: [
$class: 'ConditionalStatusResultSource',
results: [
[$class: 'BetterThanOrEqualBuildResult', result: 'SUCCESS', state: 'SUCCESS', message: build.description],
[$class: 'BetterThanOrEqualBuildResult', result: 'FAILURE', state: 'FAILURE', message: build.description],
[$class: 'AnyBuildResult', state: 'FAILURE', message: 'Loophole']
]
]
])
} Change LogDevelopmentStart the local Jenkins instance:
Jenkins Plugin Maven goals
How to installRun
to create the plugin .hpi file. To install:
Plugin releases
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论