Skip to content

JENKINS-60630: Add GitSCMFileSystem support for EnvVar expansion#1040

Closed
rayvincent2 wants to merge 3 commits intojenkinsci:masterfrom
rayvincent2:feature/git-scm-filesystem-envvar-expansion
Closed

JENKINS-60630: Add GitSCMFileSystem support for EnvVar expansion#1040
rayvincent2 wants to merge 3 commits intojenkinsci:masterfrom
rayvincent2:feature/git-scm-filesystem-envvar-expansion

Conversation

@rayvincent2
Copy link

JENKINS-60630 - Perform EnvVars expansion on GitSCMFileSystem BranchSpecs

Updates the GitSCMFileSystem class to support expanding environment variables on provided BranchSpecs.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. This is simply a reminder of what we are going to look for before merging your code. If a checkbox or line does not apply to this pull request, delete it. We prefer all checkboxes to be checked before a pull request is merged

  • I have read the CONTRIBUTING doc
  • I have referenced the Jira issue related to my changes in one or more commit messages
  • I have added tests that verify my changes
  • Unit tests pass locally with my changes
  • I have added documentation as necessary
  • No Javadoc warnings were introduced with my changes
  • No spotbugs warnings were introduced with my changes
  • Documentation in README has been updated as necessary
  • Online help has been added and reviewed for any new or modified fields
  • I have interactively tested my changes
  • Any dependent changes have been merged and published in upstream modules (like git-client-plugin)

Types of changes

What types of changes does your code introduce? Put an x in the boxes that apply. Delete the items in the list that do not apply

  • Dependency or infrastructure update
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Further comments

One concern that I have is the approach for retrieving Environment Variables for the running job. I referenced the lastBuild when isBuilding() is true. This will create a race condition during concurrent builds (depending on how the SCM API is used) where all running builds will only use the environment variables for the last one initiated. I've confirmed this on my local Jenkins server.

The only way I see to resolve this is to update the SCM API's SCMFileSystem.Builder.build api to allow for a new override:

public abstract SCMFileSystem build(@NonNull Run<?,?> run, @NonNull SCM scm, @CheckForNull SCMRevision rev)
                throws IOException, InterruptedException;

This would allow anyone to reference the exact build that's being executed and easily infer the Item needed as well. In addition, the existing method can use the lastBuild as a best effort.

Before diving into dependent libraries, I wanted to get another eye on this. As is, this works great aside from the potential issue of concurrent jobs.

@rayvincent2 rayvincent2 force-pushed the feature/git-scm-filesystem-envvar-expansion branch from 578ca39 to c68769e Compare February 26, 2021 22:52
@MarkEWaite MarkEWaite added the enhancement Improvement or new feature label Apr 10, 2021
@MarkEWaite
Copy link
Contributor

jenkinsci/workflow-cps-plugin#577 and #1305 resolve this once the workflow-cps plugin release is available. A pre-release build of workflow-cps plugin has been generated with jenkinsci/workflow-cps-plugin#633

@MarkEWaite MarkEWaite closed this Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement or new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants