Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that scm env variables are set for declarative pipeline. #286

Closed

Conversation

Globegitter
Copy link

I had an issue in my Jenkins setup that I did not have access to GIT_COMMIT etc variables in my declarative pipeline. And it was a mystery to me as I have the latest versions of all plugins and that should be working. Turns out that the kubernetes declarative agant is not support it.

I just copied some of the relevant bits of code from: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/fd56764049461eca7c27a976446f5e053ea3aefe/pipeline-model-extensions/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy as well as the corresponding test. There might be a better way of doing this but this is the first time for me writing any groovy and contributing to anything related to jenkins. Also for some reason I could not run the test locally. But I have compiled the plugin and tested it in our jenkins deployment. Finally the SCM env variables work again as expected.

Just let me know if I should improve anything anywhere, but would be great to get this fix in.

@Globegitter
Copy link
Author

Not sure why the test is failing. Is this maybe not running the pipeline within the context of a git repository? I suppose I have to pull in import jenkins.plugins.git.GitSampleRepoRule;, is that the right direction to go? If so happy to amend and fix the test.

@carlossg
Copy link
Contributor

Related to #283 ?

@Globegitter
Copy link
Author

Yeah seems related, but not sure if that PR would make the scm variables available. I will test it out tomorrow though.

Copy link
Contributor

@carlossg carlossg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess((r.waitForCompletion(b)));
r.assertLogNotContains("GIT_COMMIT is null", b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also check that log contains GIT_COMMIT is

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@Globegitter
Copy link
Author

@carlossg Yes I was not sure yesterday how to ensure the pipeline is set-up against a git repo so the scm step is actually being run, but will look into that today.

@Globegitter
Copy link
Author

@carlossg Fixed the tests. Let me know if I should do anything else.

pom.xml Outdated
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- KubernetesDeclarativeAgentTest -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated

@carlossg
Copy link
Contributor

@abayer would love your declarative review

@carlossg carlossg requested a review from abayer March 6, 2018 10:04
@nlowe
Copy link

nlowe commented Jul 16, 2018

We got bit by this today. Building in k8s is ideal for some of our projects but not having access to SCM Environment Variables greatly complicates a few things for some of our teams. Are there plans to review this again and potentially merge it? Is there an issue I can follow that's tracking this?

Copy link
Member

@abayer abayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed the review ping originally - looks good once the conflict is resolved

@carlossg
Copy link
Contributor

test is failing, maybe a merge issue

@carlossg
Copy link
Contributor

why close it @Globegitter ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants