[JIRA] (JENKINS-49786) Jenkins uses the same directory for Jenkinsfile pull and project workspace, branches are mixed up

0 views
Skip to first unread message

zimin@heavysoft.ru (JIRA)

unread,
Feb 28, 2018, 12:07:02 AM2/28/18
to jenkinsc...@googlegroups.com
Anton Zimin created an issue
 
Jenkins / Bug JENKINS-49786
Jenkins uses the same directory for Jenkinsfile pull and project workspace, branches are mixed up
Issue Type: Bug Bug
Assignee: Mark Waite
Attachments: 2018-02-28_1145.png
Components: git-client-plugin, pipeline
Created: 2018-02-28 05:06
Priority: Minor Minor
Reporter: Anton Zimin

Jenkins 2.89.3
Git client plugin 2.7.1
Git plugin 3.8.0
Pipeline 2.5


Create pipeline from SCM, use wrong as local branch name.

Jenkinsfile:


pipeline {
    agent any

    stages {
        stage ('SCM') {
            steps {
                script {
                    echo '1'
                    bat script: 'git remote -v'
                    bat script: 'git branch'

                    checkout([$class: 'GitSCM', branches: [[name: 'develop']],
                        extensions: [[$class: 'LocalBranch', localBranch: 'expected']],
                        //extensions: [[$class: 'LocalBranch', localBranch: 'expected'], [$class: 'WipeWorkspace']],
                        userRemoteConfigs: [[url: 'ssh://gitblit.example.com/anton/jenkins-project.git',
                            credentialsId: 'jenkins-ssh-credential']]])

                    echo '2'
                    bat script: 'git remote -v'
                    bat script: 'git branch'
                }
            }
        }
    }
}

First build (Log1.txt)

Branches after Jenkinsfile checkout:

* wrong

Branches after project repo checkout:

* expected
  wrong

An unexpected branch wrong exists in the list.

Second build (Log2.txt)

Branches after Jenkinsfile checkout:

  expected
* wrong

An unexpected branch expected exists in the list.

Branches after project repo checkout:

* expected
  wrong

An unexpected branch wrong exists in the list.

Build with WipeWorkspace extension (LogWipe.txt)

Branches after Jenkinsfile checkout:

* wrong
* expected

Everything is good, but I don't need to clone the repository every time.


1. Why does Jenkins use my workspace to checkout Jenkisfile? I expect it to use a temp dir, like libLoader does.
2. Why does it mix branches for unrelated repositories? Does it manually change .git/ content somehow?

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

zimin@heavysoft.ru (JIRA)

unread,
Feb 28, 2018, 12:08:01 AM2/28/18
to jenkinsc...@googlegroups.com
Anton Zimin updated an issue
Change By: Anton Zimin
Attachment: Log1.txt
Attachment: Log2.txt
Attachment: LogWipe.txt

zimin@heavysoft.ru (JIRA)

unread,
Feb 28, 2018, 12:15:02 AM2/28/18
to jenkinsc...@googlegroups.com
Anton Zimin updated an issue
Jenkins 2.89.3
Git client plugin 2.7.1
Git plugin 3.8.0
Pipeline 2.5
----

Create pipeline from SCM, use *wrong* as local branch name.



!2018-02-28_1145.png!



Jenkinsfile:
{code:java}


pipeline {
    agent any

    stages {
        stage ('SCM') {
            steps {
                script {
                    echo '1'
                    bat script: 'git remote -v'
                    bat script: 'git branch'

                    checkout([$class: 'GitSCM', branches: [[name: 'develop']],
                     extensions: [[$class: 'LocalBranch', localBranch: 'expected']],
                     //extensions: [[$class: 'LocalBranch', localBranch: 'expected'], [$class: 'WipeWorkspace']],
                     userRemoteConfigs: [[url: 'ssh://gitblit.example.com/anton/jenkins-project.git',
                     credentialsId: 'jenkins-ssh-credential']]])

                    echo '2'
                    bat script: 'git remote -v'
                    bat script: 'git branch'
                }
            }
        }
    }
}{code}

*First build (Log1.txt)*

Branches after Jenkinsfile checkout:
{code}
* wrong
{code}


Branches after project repo checkout:
{code}
* expected
  wrong
{code}

An unexpected branch *wrong* exists in the list.

*Second build (Log2.txt)*

Branches after Jenkinsfile checkout:
{code}
  expected
* wrong
{code}

An unexpected branch *expected* exists in the list.


Branches after project repo checkout:
{code}
* expected
  wrong
{code}

An unexpected branch *wrong* exists in the list.

*Build with WipeWorkspace extension (LogWipe.txt)*

Branches after Jenkinsfile checkout:
{code}
* wrong
{code}

{code}
* expected
{code}


Everything is good, but I don't need to clone the repository every time.

----


1. Why does Jenkins use my workspace to checkout Jenkisfile? I expect it to use a temp dir, like libLoader does.
2. Why does it mix branches for unrelated repositories? Does it manually change .git/ content somehow?

Similar issue: JENKINS-30619

zimin@heavysoft.ru (JIRA)

unread,
Feb 28, 2018, 12:19:03 AM2/28/18
to jenkinsc...@googlegroups.com
PruneStaleBranch extension does not help (I guess it deletes only tracked branches).

----

1. Why does Jenkins use my workspace to checkout Jenkisfile? I expect it to use a temp dir, like libLoader does.
2. Why does it mix branches for unrelated repositories? Does it manually change .git/ content somehow?

Similar issue: JENKINS-30619

mark.earl.waite@gmail.com (JIRA)

unread,
Mar 6, 2018, 9:57:02 AM3/6/18
to jenkinsc...@googlegroups.com
Mark Waite resolved as Not A Defect
 

This is behaving as expected.

Declarative Pipeline (which is what you are using) begins with an implicit checkout of the repository using the repository definition from the Jenkins job.

In your case, the implicit checkout will create a branch named "wrong" in the workspace at the most recent commit on the origin/develop branch. Refer to skipDefaultCheckout in the Declarative Pipeline options if you do not need the default checkout.

The default checkout does not seem useful in your example since the checkout in the Jenkinsfile is reusing the workspace directory. Most Declarative Pipeline users use the default checkout to avoid cluttering the Jenkinsfile with a checkout definition. If additional checkout calls are needed, they are typically performed into new subdirectories of the workspace.

If you want the branch name in the implicit checkout to match the name provided in "Branches to build", the online help says to either leave the field blank or use the value '**'.

Change By: Mark Waite
Status: Open Resolved
Resolution: Not A Defect

mark.earl.waite@gmail.com (JIRA)

unread,
Mar 6, 2018, 10:04:03 AM3/6/18
to jenkinsc...@googlegroups.com

zimin@heavysoft.ru (JIRA)

unread,
Mar 7, 2018, 7:13:02 AM3/7/18
to jenkinsc...@googlegroups.com

The default checkout does not seem useful in your example since the checkout in the Jenkinsfile is reusing the workspace directory.

I want to use Pipeline script from SCM option. That's why I need the default checkout.

If additional checkout calls are needed, they are typically performed into new subdirectories of the workspace.

Thanks, that solves the problem. Need to use ws statement in all stages that work with the second checkout.

ws ('another-workspace') {
checkout ...
}

mark.earl.waite@gmail.com (JIRA)

unread,
Jul 14, 2019, 8:08:02 AM7/14/19
to jenkinsc...@googlegroups.com
Mark Waite closed an issue as Not A Defect
 
Change By: Mark Waite
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)
Reply all
Reply to author
Forward
0 new messages