从Jenkinsfile中获取有关其他分支的信息

时间:2018-05-02 18:59:34

标签: git jenkins continuous-integration bitbucket jenkins-pipeline

Jenkins Blue Ocean与链接的Bitbucket Server实例在同一本地网络上运行。 Jenkins中的一个多分支项目能够为本地Bitbucket Server上链接的Bitbucket存储库的每个分支创建一个分支。但是在Jenkinsfile中,我无法获得有关其他分支的信息。

  

需要向简化的Jenkinsfile添加哪些特定语法才能生成控制台日志:
      1.打印远程存储库中所有分支的完整列表,以及
      2.过滤列表以仅包括标题包含特定子字符串xyx

的分支

这个问题询问Bitbucket对象模型中的Bitbucket存储库分支信息,该信息应该可以通过Bitbucket API或CLI访问。

<小时/>的 Jenkinsfile <小时/>

Jenkinsfile的简化代码如下。请注意,我已经尝试了几种方法:

node {
    // Clean workspace before doing anything
    deleteDir()

    try {
        stage ('Clone') {
            def repoUrl = checkout(scm).GIT_URL
            sh "echo 'The repo URL is: ${repoUrl}'"
            def branch = checkout(scm).GIT_BRANCH
            sh "echo 'The name of the branch containing the commit for this build is: ${branch}'"
            sh "git remote show"
            sh "git remote show origin"
        }
    } catch (err) {
        currentBuild.result = 'FAILED'
        throw err
    }
}

前面的Jenkinsfile并未隔离预期的信息。


日志

运行前面的Jenkinsfile产生的完整日志如下:

General SCM<1s
    Cloning the remote Git repository
    Cloning with configured refspecs honoured and without tags
    Cloning repository http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
     > git init /var/jenkins_home/workspace/ne_GWS-43-getissueforcommit-M2X23QGNMETLDZWFK7IXVZQRCNSWYNTDFJZU54VP7DMIOD6Z4DGA # timeout=10
    Fetching upstream changes from http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
     > git --version # timeout=10
    using GIT_ASKPASS to set credentials Bitbucket server credentials
     > git fetch --no-tags --progress http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git +refs/heads/GWS-43-getissueforcommit:refs/remotes/origin/GWS-43-getissueforcommit
     > git config remote.origin.url http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git # timeout=10
     > git config --add remote.origin.fetch +refs/heads/GWS-43-getissueforcommit:refs/remotes/origin/GWS-43-getissueforcommit # timeout=10
     > git config remote.origin.url http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git # timeout=10
    Cleaning workspace
     > git rev-parse --verify HEAD # timeout=10
    No valid HEAD. Skipping the resetting
     > git clean -fdx # timeout=10
    Fetching without tags
    Fetching upstream changes from http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
    using GIT_ASKPASS to set credentials Bitbucket server credentials
     > git fetch --no-tags --progress http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git +refs/heads/GWS-43-getissueforcommit:refs/remotes/origin/GWS-43-getissueforcommit
    Checking out Revision 146a9be9f1500df335614cc7d769d14e6de16649 (GWS-43-getissueforcommit)
     > git config core.sparsecheckout # timeout=10
     > git checkout -f 146a9be9f1500df335614cc7d769d14e6de16649
     > git branch -a -v --no-abbrev # timeout=10
     > git checkout -b GWS-43-getissueforcommit 146a9be9f1500df335614cc7d769d14e6de16649
    Commit message: "remove extraneous info"
     > git rev-list --no-walk ecb67a432da567cf2e6d91f031b8ceb2f59ed087 # timeout=10
    Cleaning workspace
     > git rev-parse --verify HEAD # timeout=10
    Resetting working tree
     > git reset --hard # timeout=10
     > git clean -fdx # timeout=10
    [Bitbucket] Notifying commit build result

echo 'The repo URL is: http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git'— Shell Script<1s
    [ne_GWS-43-getissueforcommit-M2X23QGNMETLDZWFK7IXVZQRCNSWYNTDFJZU54VP7DMIOD6Z4DGA] Running shell script
    + echo The repo URL is: http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
    The repo URL is: http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git

General SCM<1s
    > git rev-parse --is-inside-work-tree # timeout=10
    Fetching changes from the remote Git repository
     > git config remote.origin.url http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git # timeout=10
    Cleaning workspace
     > git rev-parse --verify HEAD # timeout=10
    Resetting working tree
     > git reset --hard # timeout=10
     > git clean -fdx # timeout=10
    Fetching without tags
    Fetching upstream changes from http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
     > git --version # timeout=10
    using GIT_ASKPASS to set credentials Bitbucket server credentials
     > git fetch --no-tags --progress http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git +refs/heads/GWS-43-getissueforcommit:refs/remotes/origin/GWS-43-getissueforcommit
    Checking out Revision 146a9be9f1500df335614cc7d769d14e6de16649 (GWS-43-getissueforcommit)
     > git config core.sparsecheckout # timeout=10
     > git checkout -f 146a9be9f1500df335614cc7d769d14e6de16649
     > git branch -a -v --no-abbrev # timeout=10
     > git branch -D GWS-43-getissueforcommit # timeout=10
     > git checkout -b GWS-43-getissueforcommit 146a9be9f1500df335614cc7d769d14e6de16649
    Commit message: "remove extraneous info"
    Cleaning workspace
     > git rev-parse --verify HEAD # timeout=10
    Resetting working tree
     > git reset --hard # timeout=10
     > git clean -fdx # timeout=10
    [Bitbucket] Notifying commit build result

echo 'The name of the branch containing the commit for this build is: GWS-43-getissueforcommit'— Shell Script<1s
    [ne_GWS-43-getissueforcommit-M2X23QGNMETLDZWFK7IXVZQRCNSWYNTDFJZU54VP7DMIOD6Z4DGA] Running shell script
    + echo The name of the branch containing the commit for this build is: GWS-43-getissueforcommit
    The name of the branch containing the commit for this build is: GWS-43-getissueforcommit

git remote show— Shell Script<1s
    [ne_GWS-43-getissueforcommit-M2X23QGNMETLDZWFK7IXVZQRCNSWYNTDFJZU54VP7DMIOD6Z4DGA] Running shell script
    + git remote show
    origin

git remote show origin— Shell Script<1s
    [ne_GWS-43-getissueforcommit-M2X23QGNMETLDZWFK7IXVZQRCNSWYNTDFJZU54VP7DMIOD6Z4DGA] Running shell script
    + git remote show origin
    fatal: could not read Username for 'http://<bitbucket-ip-on-lan>:7990': No such device or address
    script returned exit code 128

0 个答案:

没有答案