[JIRA] (JENKINS-52806) Pipeline: Parallel syncs don't set environment variables properly.

3 views
Skip to first unread message

williambrode@gmail.com (JIRA)

unread,
Jul 30, 2018, 6:10:03 PM7/30/18
to jenkinsc...@googlegroups.com
William Brode created an issue
 
Jenkins / New Feature JENKINS-52806
Pipeline: Parallel syncs don't set environment variables properly.
Issue Type: New Feature New Feature
Assignee: Unassigned
Components: p4-plugin
Created: 2018-07-30 22:09
Environment: CloudBees Jenkins Enterprise 2.107.2.1-rolling, P4 plugin 1.8.9
Priority: Major Major
Reporter: William Brode

The following scripted pipeline prints out a map of the environment variables returned by by each p4 checkout run in parallel.  The map in both cases contains the client from the second checkout (Client_2) as the value for P4_CLIENT.

node() {
    parallel ([ BranchOne: {
        node {
            def scmVars = checkout poll: false,
                        scm: perforce(credential: "Credential",
                                populate: syncOnly(force: false,
                                        have: true,
                                        modtime: false,
                                        parallel: [enable: true, minbytes: '0', minfiles: '0', threads: '0'],
                                        pin: "",
                                        quiet: true,
                                        revert: false),
                                workspace: manualSpec(charset: 'none',
                                        name: 'Client_1',
                                        pinHost: false,
                                        spec: clientSpec(allwrite: false,
                                                backup: false,
                                                clobber: true,
                                                compress: false,
                                                line: 'LOCAL',
                                                locked: false,
                                                modtime: false,
                                                rmdir: true,
                                                serverID: '',
                                                streamName: "//stream",
                                                type: 'WRITABLE',
                                                view: "")))
            echo "${scmVars}"
        }
    }, BranchTwo: {
        node {
            def scmVars2 = checkout poll: false,
                        scm: perforce(credential: "Credential",
                                populate: syncOnly(force: false,
                                        have: true,
                                        modtime: false,
                                        parallel: [enable: true, minbytes: '0', minfiles: '0', threads: '0'],
                                        pin: "",
                                        quiet: true,
                                        revert: false),
                                workspace: manualSpec(charset: 'none',
                                        name: 'Client_2',
                                        pinHost: false,
                                        spec: clientSpec(allwrite: false,
                                                backup: false,
                                                clobber: true,
                                                compress: false,
                                                line: 'LOCAL',
                                                locked: false,
                                                modtime: false,
                                                rmdir: true,
                                                serverID: '',
                                                streamName: "//stream",
                                                type: 'WRITABLE',
                                                view: "")))
            echo "${scmVars2}"
        }
    }])
}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

pallen@perforce.com (JIRA)

unread,
Jul 31, 2018, 4:26:01 AM7/31/18
to jenkinsc...@googlegroups.com
Paul Allen commented on New Feature JENKINS-52806
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

Please can you raise this with CloudBees (assuming you have support).  There is a chance it is a bug in the p4-plugin. The plugin implements checkout, but the code for environment and managing parallel operations is in Jenkins core.

The plugin implements createSCM() in org.jenkinsci.plugins.p4.workflow.P4Step (which extends SCMStep) and that should return a new PerforceScm object.

Kind regards,

Paul

williambrode@gmail.com (JIRA)

unread,
Jul 31, 2018, 5:13:03 PM7/31/18
to jenkinsc...@googlegroups.com

I took a look at the p4-plugin code and believe I know why the bug occurs.  That's why I came here first.  In PerforceScm.java:buildEnvVars it is grabbing the last tagAction and then using the values from that to return to jenkins core.  This should instead be using local variables to generate the build environment since this will ensure its getting the values from this instantiation of the PerforceScm rather than another one.  I verified that the Git plugin handles it this way rather than using last tag action.  In the pipeline example above, I believe it is calling checkout() in parallel so there are 2 tag actions added.  Then it runs buildEnvVars() in parallel and both return the same set of variables (the last tag action). 

I'm assuming its worked up till now since it wasn't possible for multiple checkout() calls to be called and then multiple buildEnvVars() calls (except perhaps with multiscm which it would be okay to use the last environment anyways).

Does that satisfy you that the issue is in the p4-plugin?

Thanks,

Will

pallen@perforce.com (JIRA)

unread,
Aug 1, 2018, 5:23:02 AM8/1/18
to jenkinsc...@googlegroups.com

Hi Will,

Thank you for looking into the issue; it would seem that the bug is in the p4-plugin, I'll see what alternatives their are to tagAction.  I seem to remember that I may need access to some previous build data, but I can set those environment variables independently.

pallen@perforce.com (JIRA)

unread,
Aug 1, 2018, 5:24:02 AM8/1/18
to jenkinsc...@googlegroups.com

pallen@perforce.com (JIRA)

unread,
Aug 1, 2018, 5:24:02 AM8/1/18
to jenkinsc...@googlegroups.com
Paul Allen started work on New Feature JENKINS-52806
 
Change By: Paul Allen
Status: Open In Progress

pallen@perforce.com (JIRA)

unread,
Aug 1, 2018, 5:24:02 AM8/1/18
to jenkinsc...@googlegroups.com

jenkins.io@matthew-dews.com (JIRA)

unread,
Nov 30, 2018, 5:19:02 PM11/30/18
to jenkinsc...@googlegroups.com
Matthew Dews commented on New Feature JENKINS-52806
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

Is this issue still actively being worked on? I've run into this where the P4_CLIENT environment variable is the client from the second checkout. Here's the declarative pipeline I'm using:

 

#!groovy

pipeline {
	agent none

	stages {
		stage("Build Windows and macOS") {
			parallel {

				stage("Windows: Checkout") {
					agent {
						label "windows"
					}

					stages {
						stage("Windows: Build") {
							steps {
								echo "Hello from the Windows build"
								bat """
									dir
									echo %P4_PORT%
									echo %P4_USER%
									echo %P4_CLIENT%
								"""
							}
						}
					}
				}


				stage("macOS: Checkout") {
					agent {
						label "macOS"
					}

					stages {
						stage("macOS: Build") {
							steps {
								sh """
									echo $P4_PORT
									echo $P4_USER
									echo $P4_CLIENT
								"""
							}
						}

					}
				}
			}
		}
	}
}
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

kwirth@perforce.com (JIRA)

unread,
Dec 5, 2018, 12:27:02 PM12/5/18
to jenkinsc...@googlegroups.com

kwirth@perforce.com (JIRA)

unread,
Dec 5, 2018, 12:29:02 PM12/5/18
to jenkinsc...@googlegroups.com
Karl Wirth commented on New Feature JENKINS-52806
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

Hi Matthew Dews, I need to test with 1.9.5 nightly to see if the recent parallel changes has made any difference. Will get back to you with my findings.

kwirth@perforce.com (JIRA)

unread,
Dec 5, 2018, 12:29:03 PM12/5/18
to jenkinsc...@googlegroups.com

kwirth@perforce.com (JIRA)

unread,
Dec 7, 2018, 1:41:02 PM12/7/18
to jenkinsc...@googlegroups.com
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

Hi Matthew Dews, I've just tested with 1.9.5 (released last night) and for me I see the correct client name if I am doing an explicit checkout as mentioned in the first example.

However for implicit checkout as in your example the problem is still there:

[Master: Checkout]       //depot/parrallel_pipeline2/... //jenkins-master-Pipeline_Docker_Test2-0/...
...
[Master: Checkout] [Pipeline_Docker_Test2] Running shell script
[Master: Checkout] + echo jenkins-dockervm-00000kgxgj1jh-Pipeline_Docker_Test2-0

[Docker: Checkout]       //depot/parrallel_pipeline2/... //jenkins-dockervm-00000kgxgj1jh-Pipeline_Docker_Test2-0/...
...
[Docker: Checkout] [Pipeline_Docker_Test2] Running shell script
[Docker: Checkout] + echo jenkins-dockervm-00000kgxgj1jh-Pipeline_Docker_Test2-0

As you can see I have a test running on the master server and one on the docker slave but my echo '$P4_CLIENT' on the master responds with the docker client name.

 

Reproduction steps:

(1) Create a pipeline job that gets Jenkinsfile from comment-354997

(2) Run job.

(3) Check P4_CLIENT output from both nodes. The 1st P4_CLIENT will be the same as the second.

Marking as P4_VERIFY again for devs.

 

kwirth@perforce.com (JIRA)

unread,
Dec 7, 2018, 1:41:02 PM12/7/18
to jenkinsc...@googlegroups.com

kwirth@perforce.com (JIRA)

unread,
Dec 10, 2018, 4:57:02 AM12/10/18
to jenkinsc...@googlegroups.com
Karl Wirth assigned an issue to Unassigned
Change By: Karl Wirth
Assignee: Karl Wirth

kwirth@perforce.com (JIRA)

unread,
Dec 10, 2018, 6:23:03 AM12/10/18
to jenkinsc...@googlegroups.com

kwirth@perforce.com (JIRA)

unread,
Dec 10, 2018, 6:23:03 AM12/10/18
to jenkinsc...@googlegroups.com

kwirth@perforce.com (JIRA)

unread,
Apr 17, 2019, 10:36:03 AM4/17/19
to jenkinsc...@googlegroups.com
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

Matthew Dews has chased this. Pinging this to bring it back to the top of the list. Project management please review during the next

kwirth@perforce.com (JIRA)

unread,
Apr 17, 2019, 10:37:02 AM4/17/19
to jenkinsc...@googlegroups.com
Karl Wirth edited a comment on New Feature JENKINS-52806
[~matthew_dews] has chased this. Pinging this to bring it back to the top of the list. Project management please review during the next release planning session.

kwirth@perforce.com (JIRA)

unread,
Apr 30, 2019, 5:05:02 AM4/30/19
to jenkinsc...@googlegroups.com

jenkins.io@matthew-dews.com (JIRA)

unread,
May 14, 2019, 10:25:02 AM5/14/19
to jenkinsc...@googlegroups.com

Thanks Karl Wirth. We'd really like to swith to the declarative pipeline from freestyle jobs and use more of the p4 plugin but this is the main feature holding us back.

williambrode@gmail.com (JIRA)

unread,
Jul 30, 2019, 6:26:02 PM7/30/19
to jenkinsc...@googlegroups.com

williambrode@gmail.com (JIRA)

unread,
Jul 30, 2019, 6:41:03 PM7/30/19
to jenkinsc...@googlegroups.com
William Brode commented on New Feature JENKINS-52806
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

To celebrate the one year anniversary of this bug - I've opened a pull request

https://github.com/jenkinsci/p4-plugin/pull/104

jenkins.io@matthew-dews.com (JIRA)

unread,
Oct 7, 2019, 3:04:03 PM10/7/19
to jenkinsc...@googlegroups.com

Thanks for opening a PR for this William Brode. Has there been an opportunity to add tests in order to get this merged in? We had a request to change to our Jenkins workflow come in recently but we are unable to complete it because of this issue.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

williambrode@gmail.com (JIRA)

unread,
Oct 7, 2019, 6:47:02 PM10/7/19
to jenkinsc...@googlegroups.com

I haven't had time to write tests for it yet - but its still something I plan to do eventually (unless someone else wants to take up the work).  What was the planned change to the workflow?  I can likely just redo the changes if you're worried about losing them.

williambrode@gmail.com (JIRA)

unread,
Oct 7, 2019, 6:50:03 PM10/7/19
to jenkinsc...@googlegroups.com

Oh, sorry - you are just wanting the fix so you can use the plugin huh?  I could probably look at it in 1-2 weeks if that helps.  Always more motivating to know someone is interested in the fix.

jenkins.io@matthew-dews.com (JIRA)

unread,
Oct 10, 2019, 1:59:03 PM10/10/19
to jenkinsc...@googlegroups.com

That'd be great. Currently we maintain separate Jenkinsfiles for CI jobs across different platform's CI so that they can run at the same time, while avoiding this bug.

williambrode@gmail.com (JIRA)

unread,
Oct 10, 2019, 2:16:03 PM10/10/19
to jenkinsc...@googlegroups.com

Yeah, we basically do the same.  I can't promise anything but I'll do my best to get to this in 2 weeks.

pallen@perforce.com (JIRA)

unread,
Oct 14, 2019, 11:03:03 AM10/14/19
to jenkinsc...@googlegroups.com

Hi guys,  I have merged the original pull request and added a test case to test parallel stages.

williambrode@gmail.com (JIRA)

unread,
Oct 14, 2019, 1:17:03 PM10/14/19
to jenkinsc...@googlegroups.com

Awesome, thanks Paul!  I'll be sure to add a test for my next pull request.

pallen@perforce.com (JIRA)

unread,
Oct 15, 2019, 4:27:03 AM10/15/19
to jenkinsc...@googlegroups.com

pallen@perforce.com (JIRA)

unread,
Oct 25, 2019, 10:59:03 AM10/25/19
to jenkinsc...@googlegroups.com
 

Released in 1.10.6

Change By: Paul Allen
Status: In Review Closed
Resolution: Fixed

alisdair.robertson@seeingmachines.com (JIRA)

unread,
Nov 5, 2019, 10:50:03 PM11/5/19
to jenkinsc...@googlegroups.com
Alisdair Robertson commented on New Feature JENKINS-52806
 
Re: Pipeline: Parallel syncs don't set environment variables properly.

Prior to this change the p4sync step yielded a map of the env vars, I'm using this in many pipeline scripts. After updating to 1.10.6 from 1.10.4 the p4sync step returns an empty map (breaking my pipeline scripts!)

Was this expected?

kwirth@perforce.com (JIRA)

unread,
Nov 6, 2019, 5:12:02 AM11/6/19
to jenkinsc...@googlegroups.com

Hi Alisdair Robertson - I've created a new bug to look into this - JENKINS-60074. Will let you know what I find from that bug.

Reply all
Reply to author
Forward
0 new messages