2016-12-07 51 views
0

作爲Jenkins管道構建的一部分,我檢出了我的repo(複製到我可以看到的工作區)。然後我修改了我工作區中的一個文件,然後我想推回到我的github回購。我剛剛更新的podspec文件版本號將工作區中的修改後的文件推送到github

node { 
    stage 'Update File' 
    env.WORKSPACE = pwd() 
    File file = new File("${env.WORKSPACE}/ios.podspec"); 
    fileText = file.text; 
    regex = "(spec.version\\s.*\$)"; 
    fileText = fileText.replaceAll(regex, "spec.version    = '${VERSION}'\n".trim()); 
    file.write(fileText); 

} 

我如何可以採取的文件,將其推回了我的混帳回購協議

如果有人能夠幫助這將是非常讚賞

由於

+0

是在'.gitignore'列出的文件?你是否也可以在本地修改該文件並提交更改? – nullpointer

+0

不,它不是,所以不知道我錯過了什麼,是的,我可以在本地更新 – Richlewis

+0

很簡單,通過提交文件並推送更改。你有一個本地簽出版本,你可能需要設置你的遠程(我認爲默認是從遠程分離),但除此之外,它只是正常的git。選擇一個適合你的管道的工具並執行這些命令。 – gpgekko

回答

1
sh "git checkout $branch" 
sh "git add <your file>" 
sh "git commit -m '...'" 
sh "git push $url $branch" 

棘手的部分是設置的URL與相關憑證 我用這方法 -

def getRemoteUrlWithCredentials(credentialsId) { 
    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: credentialsId, usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { 
     def scmUrl = scm.getUserRemoteConfigs()[0].getUrl() 
     scmUrl = scmUrl.substring(scmUrl.indexOf("github.com")) 
     return "https://${GIT_USERNAME}:${GIT_PASSWORD}@${scmUrl}" 
    } 
} 

其中credentialId是您的git credentialsId。您需要將scm.getUserRemoteConfigs添加到Manage Jenkins中的批准列表 - >處理腳本批准中。

而最後一部分 - 我不知道這是否是必要的,但也許你需要設置config user.email和user.name - >

def setupConfig(email, userName) { 
    sh "git config user.email $email" 
    sh "git config user.name $userName" 
} 
+0

謝謝,最後只是用簡單的git命令工作,不需要創建方法 – Richlewis

+0

用ssh或https – Amityo

+1

ssh已經有了jenkins的設置 – Richlewis