Git 詹金斯头
我在使用Jenkins GIT插件时遇到了一个问题,因为它返回一个分离的头部。Git 詹金斯头,git,jenkins,Git,Jenkins,我在使用Jenkins GIT插件时遇到了一个问题,因为它返回一个分离的头部。 我想要完成的是: 从git存储库中提取代码 对此存储库中的特定文件进行更改 使用Jenkins将更改推送到同一存储库 要从我的存储库中提取的以下代码: checkout([ $class: 'GitSCM', branches: [[name: "branch1"]], userRemoteConfigs: [[credentialsId: "cre
我想要完成的是:
- 从git存储库中提取代码
- 对此存储库中的特定文件进行更改
- 使用Jenkins将更改推送到同一存储库
checkout([
$class: 'GitSCM',
branches: [[name: "branch1"]],
userRemoteConfigs: [[credentialsId: "credentials", url: "repository"]],
extension: [[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackinSubmodule: false
]],
submoduleCfg:[]
])
}
(Changes to file)
...
stage('Push to repo') {
steps {
sh """
git checkout master
git pull origin master
git add test.txt
git commit -m "Added string"
git push origin master
"""
}
}
要推送到我的存储库的代码:
checkout([
$class: 'GitSCM',
branches: [[name: "branch1"]],
userRemoteConfigs: [[credentialsId: "credentials", url: "repository"]],
extension: [[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackinSubmodule: false
]],
submoduleCfg:[]
])
}
(Changes to file)
...
stage('Push to repo') {
steps {
sh """
git checkout master
git pull origin master
git add test.txt
git commit -m "Added string"
git push origin master
"""
}
}
错误:
From gitlab.com:USERNAME/test-jenkins
* branch master -> FETCH_HEAD
Already up-to-date.
error: Your local changes to the following files would be overwritten by checkout:
test.txt
Please commit your changes or stash them before you switch branches.
Aborting
[detached HEAD 2adf034] Added string
1 file changed, 1 insertion(+)
如果我删除签出
:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitlab.com:USERNAME/test-jenkins.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for detail
我已尝试按照中的步骤进行操作。自从,您可以向管道中添加一个sh步骤
sh("git checkout branch1")
这将有助于在分支上操作剩余的操作,而不是在分离的头上操作。由于,您可以在管道中添加一个sh步骤
sh("git checkout branch1")
这将有助于您在剩下的操作中对分支进行操作,而不是对分离的磁头进行操作。您好,是的,所以我要做的是使用
GitSCM
进行克隆,然后我拉动origin master,它应该能正确修复它?。。我已经将GitSCM更改为一个sh
,它克隆了repo。。。当我尝试使用管道推送新代码时,我有一些错误……您好,是的,所以我要做的是使用GitSCM
进行克隆,然后我拉原始主机,它应该可以修复它?。。我已经将GitSCM更改为一个sh
,它克隆了repo。。。当我尝试使用管道推送新代码时,我遇到了一些错误。。。。。。