Skip to content

Commit

Permalink
Adding git HTTPS support
Browse files Browse the repository at this point in the history
Change the credentials parameter the GIT_CREDENTIALS instead of SSH_CREDENTAILS
It now checks the git repo for https:// or git@ to determine if it is https or ssh

Fixed adoptium#3
Signed-off-by: Samuel Rubin <samuel.rubin@ibm.com>
  • Loading branch information
samuel-rubin committed Apr 16, 2019
1 parent 3b72be4 commit 911665d
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions Jenkins_jobs/GetInventoryList.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Parameters:
SETUP_LABEL: String - the label of the node that this job runs on. The default is worker
LABEL: String - the label of the machines that this job will look for
SLACK_CHANNEL: String - What channel a list of problematic machines gets sent to. If this is empty, no slack message will be sent
SSH_CREDENTIALS: Credentials - The credentials needed to push the files to git
GIT_CREDENTIALS: Credentials - The credentials needed to push the files to git
GIT_REPO: String - The git repo to push the files to. If this is not set, the files will be archived to Jenkins
GIT_BRANCH: String - The git branch to push the files to. It defaults to master
INI_FILE: String - full path to the ini file including the filename
Expand Down Expand Up @@ -67,16 +67,36 @@ node(setupLabel){
if(params.GIT_REPO && params.GIT_BRANCH){
def date = new Date()
dir('git_repo'){
git url: params.GIT_REPO, branch: params.GIT_BRANCH, credentials: params.SSH_CREDENTIALS
git url: params.GIT_REPO, branch: params.GIT_BRANCH, credentials: params.GIT_CREDENTIALS
outputFiles.each() { file ->
sh "cp ${workspace}/${file} ${file}"
}
sshagent([params.SSH_CREDENTIALS]) {
sh """\
git add ${outputFiles.join(' ')}
git commit -m "This File has been updated on ${date} from Jenkins"
git push origin ${params.GIT_BRANCH}
"""
if (params.GIT_REPO.contains('git@')){
sshagent([params.GIT_CREDENTIALS]) {
sh """\
git add ${outputFiles.join(' ')}
git commit -m "This File has been updated on ${date} from Jenkins"
git push origin ${params.GIT_BRANCH}
"""
}
} else if (params.GIT_REPO.contains('https://')){
withCredentials([usernamePassword(credentialsId: params.GIT_CREDENTIALS, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
def GIT_PUSH_URL = 'https://' + GIT_USERNAME + ':' + GIT_PASSWORD + '@' + (params.GIT_REPO - 'https://')

sh """\
git add ${outputFiles.join(' ')}
if output=$(git status --porcelain --untracked-files=no) && [ -z "$output" ]
then
echo 'No changes found...'
else
echo 'Updates found'
git commit -m "This File has been updated on ${date} from Jenkins"
git push ${GIT_PUSH_URL} ${params.GIT_BRANCH}
fi
"""
}
} else {
error "There was a problem with the git repo. It does not contain 'https://' or 'git@'"
}
}
}
Expand Down

0 comments on commit 911665d

Please sign in to comment.