Jenkins Pipeline 常用操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaosongluo/article/details/77969271

手动拉取 Git/Svn 仓库源码

说明:使用 Pipeline 自带的 git,svn 以及 checkscm 命令会将源码仓库加入监控,当不想使用这个特性时,需要手动进行源码拉取

//git sample
withCredentials([usernamePassword(credentialsId: '37813d64-15e9-4a3c-9646-a5bfe2bd44fd', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
    sh 'git clone http://${GIT_USERNAME}:${GIT_PASSWORD}@${your_git_project_location}'
}

//svn sample
withCredentials([usernamePassword(credentialsId: '87cd2e0d-2e81-4735-b881-b49b4302bc99', passwordVariable: 'SVN_PASSWORD', usernameVariable: 'SVN_USERNAME')]) {
    sh 'svn co ${your_svn_project_location} . --username ${SVN_USERNAME} --password ${SVN_PASSWORD}'
}

提交更改至 Git/Svn 仓库

说明:发布至源码仓库时常用的功能

//git sample
sh '''
    git add --all
    git commit -am "$commit"
    git push origin master
    git tag -a "$tagname" -m "$commit"
    git push origin $tagname
'''

//svn sample
sh '''
    svn st | awk '{if ( $1 == "?") { print $2}}' | xargs -r svn add
    svn st | awk '{if ( $1 == "!") { print $2}}' | xargs -r svn rm
    svn commit -m "$commit"
    svn cp . ${your_svn_project_location}/tags/${tagname}  -m "$commit"
'''

写邮件

说明:略

mail (
    to: 'somebody@company.cn,nobody@company.cn',
    cc: 'somebody@company.cn',
    charset: 'UTF-8',
    mimeType: ' text/plain', 
    subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - SUCCESS!", 
    body: """
${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - SUCCESS:
Check console output at ${env.BUILD_URL} to view the results.
    """
)

猜你喜欢

转载自blog.csdn.net/xiaosongluo/article/details/77969271