2016-04-01 13 views

cevap

6

İşte bunu bu şekilde uygulayabildim, ama eğer daha iyi bir yolu biliyorsanız, bunu duymaktan daha fazlasıyım.

#!groovy 

stage 'build' 
node { 

    repositoryCommiterEmail = '[email protected]' 
    repositoryCommiterUsername = 'examle.com' 

    checkout scm 

    sh "echo done" 

    if (env.BRANCH_NAME == 'master') { 
     stage 'tagging' 

     sh("git config user.email ${repositoryCommiterEmail}") 
     sh("git config user.name '${repositoryCommiterUsername}'") 

     sh "git remote set-url origin [email protected]:..." 

     // deletes current snapshot tag 
     sh "git tag -d snapshot || true" 
     // tags current changeset 
     sh "git tag -a snapshot -m \"passed CI\"" 
     // deletes tag on remote in order not to fail pushing the new one 
     sh "git push origin :refs/tags/snapshot" 
     // pushes the tags 
     sh "git push --tags" 
    } 
} 
+2

Bu ilginç. Uzaktan kumandayı nasıl doğrularsınız (şifreyi nasıl gönderirsiniz)? – octavian

1

I (Git Publish Support geliştiriliyor olsa da) SSH ile repo git'e değişiklikler/etiketlerini yayınlamak için my Jenkins Pipeline Setup ve benim çözüm paylaşmak istiyorum. Daha fazla bilgi için lütfen kontrol edin, herhangi bir iyileştirme fikri kabul edilir.

Kısacası aynen bu şekilde Jenkinsfile adresinin proje ve çağrı yöntemiyle pushSSH() dosyayı git_push_ssh.groovy ekleyin: did doğrudan eklentisi ben sshagent kullanılan yukarıdaki çalışma, alamadım insanlar için

env.BRANCH_NAME = "mycoolbranch"// BRANCH_NAME is predefined in multibranch pipeline job 
env.J_GIT_CONFIG = "true" 
env.J_USERNAME = "Jenkins CI" 
env.J_EMAIL = "[email protected]" 
env.J_CREDS_IDS = '02aa92ec-593e-4a90-ac85-3f43a06cfae3' // Use credentials id from Jenkins 
def gitLib = load "git_push_ssh.groovy" 
... 
gitLib.pushSSH(commitMsg: "Jenkins build #${env.BUILD_NUMBER}", tagName: "build-${env.BUILD_NUMBER}", files: "changelog.txt someotherfile.txt"); 
1

hüner:

stage('tag build'){ 
checkout([ 
    $class: 'GitSCM', branches: [[name: '*/master']], 
    userRemoteConfigs: [[credentialsId: 'git', 
    url: 'ssh://<ssh URL>']], 
    extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'targeted-dir']] 
]) 

sshagent(credentials: ['<credentials ID.']){ 
    dir('targeted-dir'){ 
    sh("git config user.email '<email>") 
    sh("git config user.name '<user>.com'") 

    // deletes current snapshot tag 
    sh ("git tag -d ${PARAM_VERSION_NUMBER} || true") 
    // tags current changeset 
    sh ("git tag -a ${PARAM_VERSION_NUMBER} -m \"versioning ${PARAM_VERSION_NUMBER}\"") 
    // deletes tag on remote in order not to fail pushing the new one 
    sh ("git push origin :refs/tags/snapshot") 
    // pushes the tags 
    sh ("git push --tags") 
    } 
} 

}

İlgili konular