Jenkins 不使用 git 参数插件检索 git 引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28988425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins doesnt retrieve git references using git parameter plugin
提问by Kingalione
Hello I'm trying to configure our jenkins build server to use git branches.
您好,我正在尝试配置我们的 jenkins 构建服务器以使用 git 分支。
My configuration looks like this:
我的配置如下所示:
Well if I click on build with parameters I get a empty list like this:
好吧,如果我点击带参数的构建,我会得到一个像这样的空列表:
I have build this project without parameters and it worked. In the Source-Code-Management part I have added our server with the right creditials without ssh. (only username and password)
我已经在没有参数的情况下构建了这个项目并且它有效。在源代码管理部分,我在没有 ssh 的情况下添加了带有正确信用的服务器。(只有用户名和密码)
However I get no git references in the list. I have googled around and found out that this is a common issue if you use ssh but we dont use ssh. I dont want to make a workaround via Extensible Choice Parameter plugin.
但是我在列表中没有得到 git 引用。我搜索了一下,发现如果您使用 ssh 但我们不使用 ssh,这是一个常见问题。我不想通过可扩展选择参数插件来解决。
So what is the problem here? I cant believe that this is so hard to configure in jenkins...
那么这里的问题是什么?我不敢相信这在詹金斯中很难配置......
We use the latest jenkins version and git parameter plugin with the maven id: org.jenkins-ci.tools:git-parameter:0.4.0
我们使用最新的 jenkins 版本和 git 参数插件,maven id 为:org.jenkins-ci.tools:git-parameter:0.4.0
采纳答案by Jonathan Vanderick
I had the same problem, and I followed a suggestion found in a discussion: getting the latest version of the plugin (0.4.1-SNAPSHOT) from Github (https://github.com/jenkinsci/git-parameter-plugin), compile it and install it.
我遇到了同样的问题,我遵循了讨论中的一个建议:从 Github ( https://github.com/jenkinsci/git-parameter-plugin)获取最新版本的插件 (0.4.1-SNAPSHOT ),编译并安装它。
That new version of the plugin do work with SSH URL/Credentials in the job's SCM configuration in a Linux environment.
该插件的新版本确实可以在 Linux 环境中的作业的 SCM 配置中使用 SSH URL/Credentials。
回答by andreas caternberg
Here is my solution for bitbucket: (Should work with little modification of the URL for gitlab/github as well)
这是我的 bitbucket 解决方案:(也应该对 gitlab/github 的 URL 稍加修改)
You can do it with the Bitbucket Rest API and Scriptler: (Here for example with the "tags" endpoint. It works also with other endpoints such as "branches")
您可以使用 Bitbucket Rest API 和 Scriptler 来做到这一点:(这里例如使用“标签”端点。它也适用于其他端点,例如“分支”)
Go to Manage Jenkins -> Scriptler -> Add a new Script
you have to set your values for ORGANISATION, REPOSITORY, USER and PASSWORD. The best way to do is with the "Define script parameters" option in scriptler
转到管理 Jenkins -> Scriptler -> 添加新脚本
您必须设置 ORGANISATION、REPOSITORY、USER 和 PASSWORD 的值。最好的方法是使用 scriptler 中的“定义脚本参数”选项
```
``
String organization="${ORGANISATION}"
String repository="${REPOSITORY}"
String endpoint="tags"
String baseUrl = "https://api.bitbucket.org"
String version = "1.0"
// Create authorization header using Base64 encoding
//HERE YOU CAN GET THE AUTH CREDENTIALS OVER THE CREDENTIALSID INSTEAD
String userpass = "${USER}:${PASSWORD}"
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
println basicAuth
String url = [baseUrl, version, "repositories", organization, repository, endpoint].join("/")
println "URL " + url
// Create URL
URL apiUrl = url.toURL()
// Open connection
URLConnection connection = apiUrl.openConnection()
// Set authorization header
connection.setRequestProperty("Authorization", basicAuth)
InputStream inputStream = connection.getInputStream()
HashMap tags = new groovy.json.JsonSlurper().parseText(inputStream.text)
inputStream.close()
Set keys= tags.keySet();
List<String> list=new ArrayList<String>()
keys.each { key ->
println key
list.add(key)
}
return list
```
``
- Then you should add the "Dynamic Choice Parameter (Scriptler)" parameter to your job and select the scriptler which you have added before. NOTE: You have to install the Dynamic+Parameter+Plug-inbefore
- 然后您应该将“动态选择参数(脚本程序)”参数添加到您的作业中,并选择您之前添加的脚本程序。注意:您必须安装动态+参数+插件前
回答by R C
I got same "retrieving git references" but no branches. There were couple of solutions on web.
我得到了相同的“检索 git 引用”,但没有分支。网上有几个解决方案。
- run chron job which creates list of branches, saves them to filesystem and read it to display.
- run groovy script to get list of branches and display.
- 运行创建分支列表的 chron 作业,将它们保存到文件系统并读取它以显示。
- 运行 groovy 脚本以获取分支列表并显示。
My solution(which worked for me) was to download sourcecode from github for git-parameter plugin, build plugin and move to jenkins/WEB-INF/plugins. Started showing list of branches available on repo.
我的解决方案(对我有用)是从 github 下载 git-parameter 插件的源代码,构建插件并移动到 jenkins/WEB-INF/plugins。开始显示 repo 上可用的分支列表。
steps:
脚步:
- git clone https://github.com/jenkinsci/git-parameter-plugin.git
- cd git-parameter-plugin
- mvn clean package -DskipTests=true
- copy git-parameter.hpi from git-parameter-plugin\target to jenkins/WEB-INF/plugins
- restart jenkins.
- git 克隆https://github.com/jenkinsci/git-parameter-plugin.git
- cd git-parameter-plugin
- mvn clean package -DskipTests=true
- 将 git-parameter.hpi 从 git-parameter-plugin\target 复制到 jenkins/WEB-INF/plugins
- 重启詹金斯。
you should be able to see all branches now.
您现在应该能够看到所有分支。
回答by Gall Sergii
Workaround. Works fine for me. Hope plugin will be fixed soon.
解决方法。对我来说很好用。希望插件尽快修复。
- Create new item i.e."git_repo". Add Git repository. Build this project once.
- In the project you need branch/tag use, just add "file://" repository with workspace from step one: example (file:///var/lib/jenkins/jobs/git_repo/workspace)
- 创建新项目,即“git_repo”。添加 Git 存储库。构建此项目一次。
- 在需要使用分支/标签的项目中,只需在第一步中添加带有工作区的“file://”存储库:示例 (file:///var/lib/jenkins/jobs/git_repo/workspace)
In this case my project can fetch all data i need to build my project.
在这种情况下,我的项目可以获取构建项目所需的所有数据。
回答by DuncanSungWKim
If you are using Jenkins on Windows, Git Parameter Plug-In 0.4 may not work and keep showing "retrieving Git references".
如果您在 Windows 上使用 Jenkins,Git Parameter Plug-In 0.4 可能无法工作并继续显示“检索 Git 引用”。
I believe the reason is that the plug-in doesn't use Jenkins' credential but runs git commands as the system's logged-on user. You can fix it by changing JenKins' Windows service's logged on user to the real person who has logged on and saved the password in the Windows Credentials.
我认为原因是插件没有使用Jenkins的凭据,而是以系统的登录用户身份运行git命令。您可以通过将 JenKins 的 Windows 服务的登录用户更改为已登录并将密码保存在 Windows 凭据中的真实用户来修复它。
回答by Josh Kehoe
I had the same problem of "Retrieving Git references" with no Git tags, but it was not a permission issue. I'm leaving this here in case anyone else stumbles upon this link (first one in Google for the problem) and may have the same issue as me.
我在没有 Git 标签的情况下遇到了“检索 Git 引用”的相同问题,但这不是权限问题。我把这个留在这里,以防其他人偶然发现这个链接(谷歌中的第一个问题)并且可能和我有同样的问题。
When I looked in the Jenkins logs, I saw an error from the Git Parameter plugin for a Java number format error (java.lang.NumberFormatException). This was because I was using the build timestamp to create my tags, which ended up being a very long numerical value. The plugin must recognize it as numeric, then tries to convert it to an int (I assume to do the sort later), but then blows up because it is too long. To fix this, I had to remove all of my tags and change my build to tag with the name of the job plus the build number (For example, DEV-233). After I did that, the list of tags was populating correctly.
当我查看 Jenkins 日志时,我从 Git 参数插件中看到了一个 Java 数字格式错误 (java.lang.NumberFormatException) 的错误。这是因为我使用构建时间戳来创建我的标签,结果是一个很长的数值。插件必须将其识别为数字,然后尝试将其转换为 int(我假设稍后进行排序),但由于它太长而爆炸。为了解决这个问题,我必须删除所有标签并将我的构建更改为带有作业名称和构建编号的标记(例如,DEV-233)。在我这样做之后,标签列表正确填充。