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

Refactor the SCM class structure to handle GenericWebHook config #5

Closed
sandinosanchez opened this issue Oct 8, 2020 · 2 comments
Closed
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@sandinosanchez
Copy link
Contributor

In order to configure the generic webhook plugin the following configuration has to be made to the functionality of cloning a pr:
https://github.com/zebrunner/qps-pipeline/blob/be1cc52f5229edab81caca76109050f14e99b5dd/src/com/qaprosoft/jenkins/pipeline/tools/scm/github/GitHub.groovy#L112

For each SCM:

  1. prRefSpec:
    • GitHub and BitBucket server: +refs/pull/*:refs/remotes/origin/pr/*
    • Gitlab: +refs/merge-requests/*:refs/remotes/origin/merge-requests/*
  2. branchSpecifier
    • GitHub: origin/pr/${prNumber}/merge
    • Gitlab and BitBucket server: origin branch name

And on the side of the Generic Webhook jenkins plugin, a set of variables needs to be created, this variables will store the JSON path expression to acquire the information of the event being triggered and configure the PullRequestJobFactory and PushJobFactory dsl objects. Depending of the type of scm you are registering, the amount of required args for the job dsl configuration may vary.

For such configuration required, and given the current state of the SCM tools implementation, the SCM functionality needs to be refactored, maybe create a dedicate class for each scm type supported in the infra, and add there the prRefSpec, branchSpecifier and the job dsl variables needed to configure the pull request and push dsl objects.

@sandinosanchez
Copy link
Contributor Author

sandinosanchez commented Oct 22, 2020

Delivered in in:

Objectice:

  • Verify that the onPush and onPullRequest jobs are working as expected for gitlab and github.

Environment:

  • Zebrunner-CE: develop

Pre-conditions:

  • carina-demo repo forked int your github and gitlab account.

Test Scenario 1:

  1. configure sonarqube instance with github steps
  2. Go to your github profile > developer settings > personal access tokens > generate new one with repo scope selected. (make sure to copy the token)
  3. Go to your repo settings page > Webhook > And add a new one:
    - Payload URL: http://zb-domain/jenkins/generic-webhook-trigger/invoke?token=your-token-here (step 2)
    - Content type: application/json
    - Select let me send individual events and tap [Pull requests , pushes]
  4. Run RegisterOrganization
  5. Go to Dashboard > Manage Jenkins > Credentials there should be one cred that looks like: orgName-scmType-webhook-token change the value for the token generated in step 2.
  6. Run register Repository with carina-demo
  7. Go to your repo, create a branch from master and:
    • Copy this line of code at the same location in your branch(src/main/java/com/qaprosoft/carina/demo/gui/pages/HomePage.java).
    • Copy this from line 50 to 52 and paste it in the same location in your branch(src/main/java/com/qaprosoft/carina/demo/gui/pages/HomePage.java)
  8. Create the Pull Request.
  9. Go to your repository master branch, and edit somtehing from the README.MD.

Test scenario 2:

  1. Go to your gitlab profile > settings > generate new one with api, read_user, read_api, read_repository and write_repository scope selected. (make sure to copy the token)
  2. Go to sonarqube instance and login:
    1. Go to Administration > PullRequest > Gitlab > Add the token generated in step 1
  3. Go to your repository > Settings > Webhooks > And add a new one:
  4. Run RegisterOrganization
  5. Go to Dashboard > Manage Jenkins > Credentials there should be one cred that looks like: orgName-scmType-webhook-token change the value for the token generated in step 1.
  6. same as step 7 from scenario 1.
  7. same as step 8 from scenario 1.
  8. same as step 9 of scenario 1.

Test scenario 3:(see #40)

  1. Register BitBucket repository
  2. Go to your BitBucket repository page > Repository Settings(left menu) > webhooks
  3. Register a new webhook:
  4. Go to Manage Jenkins > Manage creds > look for one with "orgName-gitType-webhook-token" and change the secret text with the one used in step 3
  5. Go to your bitbucket repo and edit something on the master branch.

Expected Results:

Scenario 1 and 2 :

  • After creating the Pull Request the onPullRequest job should be triggered and the sonar analysis published onto the pr as checks for github and comments for gitlab.

Github pr
Screenshot from 2020-10-22 10-09-21

Gitlab pr
Screenshot from 2020-10-22 10-09-46

  • After pushing to the master branch the onPushJob should be triggered and executed successfully.

Scenario 3:

  1. After pushing to the master branch the onPush job should be triggered on jenkins and finished successfully.

@ghost
Copy link

ghost commented Oct 29, 2020

Tested on develop branch. Done.

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

No branches or pull requests

2 participants