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

Test Automation: Add Jenkins Pipeline Unit to the repository #93

Merged
merged 14 commits into from Aug 13, 2019

Conversation

v1v
Copy link
Contributor

@v1v v1v commented Jun 12, 2019

This PR is just a PoC using the https://github.com/jenkinsci/JenkinsPipelineUnit for the vars/infra.groovy steps.

Highlights

Tasks

  • Agree whether to move forward with the rest of steps.
  • Ask for MB in ci.jenkins.io #INFRA-2147

Proposed

  • Create simple vars/steps for the methods within the vars/infra.groovy to simplify the UTs and the maintenance in the future.

@oleg-nenashev
Copy link
Contributor

Needs an INFRA ticket to get Pipeline enabled for the repo. But thanks a lot!

@oleg-nenashev oleg-nenashev self-requested a review June 12, 2019 21:53
Copy link
Contributor

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Looks good to me. If we want to verify it, ci.jenkins.io-runner should be able to execute this pipeline

@v1v
Copy link
Contributor Author

v1v commented Jun 17, 2019

I already tried with the ci.jenkins.io-runner project but I was not able to use the declarative pipeline out of the box but the scripted pipeline to test the Jenkinsfile. It seems there are some clash dependencies when running the jenkins-runner. So, I haven't tried to solve them locally yet, not sure if someone else could potentially give a go. My master branch is now based on this PR: https://github.com/v1v/pipeline-library/ in case someone would like to try the ci.jenkins.io-runner locally and easily.

@oleg-nenashev
Copy link
Contributor

oleg-nenashev commented Jun 17, 2019 via email

Copy link
Contributor

@jglick jglick left a comment

Choose a reason for hiding this comment

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

I guess we will see if this is helpful in preventing real regressions or not.

Jenkinsfile Outdated Show resolved Hide resolved
Jenkinsfile Outdated
}
stage('Test') {
steps {
sh 'mvn clean test'
Copy link
Contributor

Choose a reason for hiding this comment

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

At least add -B; also -ntp after INFRA-2129.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave the -ntp flag as a future change until that version of maven has not been updated in the infra side.

Jenkinsfile Outdated Show resolved Hide resolved
pom.xml Outdated
<plugin>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW there were some recent changes to the archetype here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After picking up the latest changes:

The test goal didn't execute anything and I managed to find implicit version changed of the surefire.

So I had to enforce the version as the previous one:

Not sure whether that's the expected behaviour in the archetype but with the latest commit everything seems to be back to business.

Copy link
Contributor

@batmat batmat left a comment

Choose a reason for hiding this comment

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

👍 🎆

@batmat
Copy link
Contributor

batmat commented Jul 6, 2019

Added a basic test locally for testing #94, this already allows at least to catch compilation errors and so on, which is already a thing. So 👍 :shipit:

import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Test
import org.yaml.snakeyaml.Yaml
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.junit.Assert.assertTrue

class BuildPluginStepTests extends BasePipelineTest {
  static final String scriptName = 'vars/buildPlugin.groovy'
  Map env = [:]



  /**
   * Mock Infra step
   */
  class Infra implements Serializable {
    public String retrieveMavenSettingsFile(String location) { return location }
    public String runWithMaven(String cmd) { return cmd }
    public String runMaven(mvn, jdk, foo, settings) { return 'OK' }
  }

  @Override
  @Before
  void setUp() throws Exception {
    super.setUp()

    binding.setProperty('infra', new Infra())
    binding.setVariable('env', env)

    helper.registerAllowedMethod('archiveArtifacts', [Map.class], { m -> m })
    helper.registerAllowedMethod('echo', [String.class], { s -> s })
    helper.registerAllowedMethod('error', [String.class], {s ->
      updateBuildStatus('FAILURE')
      throw new Exception(s)
    })
    helper.registerAllowedMethod('findFiles', [Map.class], { String[] files = ["bom.yml", "d1/bom.yml"] })
    helper.registerAllowedMethod('pwd', [], { '/foo' })
    helper.registerAllowedMethod('pwd', [Map.class], { '/bar' })
    helper.registerAllowedMethod('readYaml', [Map.class], {
      Yaml yaml = new Yaml()
      return yaml.load(default_config_metadata)
    })
    helper.registerAllowedMethod('sh', [String.class], { s -> s })
    helper.registerAllowedMethod('writeYaml', [Map.class], { })
  }

  @Test
  void test_loading() throws Exception {
    def script = loadScript(scriptName)
  }
}

@batmat
Copy link
Contributor

batmat commented Jul 6, 2019

@rtyler That would be great if you can look into https://issues.jenkins-ci.org/browse/INFRA-2147 so the library can start being tested itself. Thanks!

@v1v
Copy link
Contributor Author

v1v commented Aug 1, 2019

@rtyler sorry for asking you here directly here, I already asked twice in the infra mailing list about it, this PR is a kind of blocked as long as https://issues.jenkins-ci.org/browse/INFRA-2147 is not done. Are there any other requirements needed to be done before working on the above task?
Thanks

@oleg-nenashev
Copy link
Contributor

I pinged in chats. It looks @batmat did the same today.
Let's use #jenkins-infra for sync-up if needed

Copy link
Member

@rtyler rtyler left a comment

Choose a reason for hiding this comment

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

@v1v please accept the suggestions and then let's merge this and see how it works!

@@ -0,0 +1,25 @@
#!/usr/bin/env groovy
pipeline {
agent {
Copy link
Member

Choose a reason for hiding this comment

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

I think this can just work on the "maven" label, and use the Azure Container Instance agents which would be much faster.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for ACI

Jenkinsfile Outdated Show resolved Hide resolved
Jenkinsfile Outdated Show resolved Hide resolved
Jenkinsfile Outdated Show resolved Hide resolved
Co-Authored-By: R. Tyler Croy <rtyler@brokenco.de>
@v1v
Copy link
Contributor Author

v1v commented Aug 6, 2019

Done, please feel free to merge it, I just double check locally that mvn clean test works fine after merging with master.

Copy link
Contributor

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

I think it is pretty good as is., but bonus points for ACI

@@ -0,0 +1,25 @@
#!/usr/bin/env groovy
pipeline {
agent {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for ACI

@oleg-nenashev oleg-nenashev changed the title PROPOSAL: enable jenkins-pipeline-unit Add Jenkins Pipeline Unit to the repository Aug 13, 2019
@oleg-nenashev
Copy link
Contributor

A bit YOLO, but 🚢 🇮🇹

@oleg-nenashev oleg-nenashev merged commit ef17729 into jenkins-infra:master Aug 13, 2019
@oleg-nenashev oleg-nenashev changed the title Add Jenkins Pipeline Unit to the repository Test Automation: Add Jenkins Pipeline Unit to the repository Aug 13, 2019
@oleg-nenashev
Copy link
Contributor

[2019-08-13T13:49:06.297Z] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[2019-08-13T13:49:06.297Z] WorkflowScript: 6: No tools specified @ line 6, column 5.
[2019-08-13T13:49:06.297Z]        tools {

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

Successfully merging this pull request may close these issues.

None yet

7 participants