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

Question about payload parameter being sent to Jenkins job #26

Closed
adamjk-dev opened this Issue Jun 4, 2014 · 9 comments

Comments

Projects
None yet
3 participants
@adamjk-dev
Copy link

adamjk-dev commented Jun 4, 2014

So, would it be possible to modify this plugin such that the payload can be sent to a parameterized Jenkins job that expects a 'payload' parameter?

This way, the Jenkins job could act accordingly on the payload/data sent in. Basically, I would like to see the entire JSON object sent by gitlab in my Jenkins job. A sample use case would be that I would like to take certain actions when a new branch is created for a project.

Or, could this plugin be modified to realize a new branch creation action and send in the branch name as a parameter or something?

@xaniasd

This comment has been minimized.

Copy link
Contributor

xaniasd commented Jun 12, 2014

👍

@xaniasd

This comment has been minimized.

Copy link
Contributor

xaniasd commented Jun 12, 2014

push events include the project_id nowadays, it would be great to have that parameter available.

{
  "before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
  "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  "ref": "refs/heads/master",
  "user_id": 4,
  "user_name": "John Smith",
  "project_id": 15,
  "repository": {
    "name": "Diaspora",
    "url": "git@example.com:diaspora.git",
    "description": "",
    "homepage": "http://example.com/diaspora"
  },
  "commits": [
    {
      "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
      "message": "Update Catalan translation to e38cb41.",
      "timestamp": "2011-12-12T14:27:31+02:00",
      "url": "http://example.com/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
      "author": {
        "name": "Jordi Mallach",
        "email": "jordi@softcatala.org"
      }
    },
    {
      "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
      "message": "fixed readme",
      "timestamp": "2012-01-03T23:36:29+02:00",
      "url": "http://example.com/diaspora/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
      "author": {
        "name": "GitLab dev user",
        "email": "gitlabdev@dv6700.(none)"
      }
    }
  ],
  "total_commits_count": 4
}
@elvanja

This comment has been minimized.

Copy link
Owner

elvanja commented Jun 13, 2014

So, there are actually a few question here:

  • expose payload in Jenkins build details
  • expose project_id from payload as parameter for the job
  • expose ref (branch name) from payload as parameter for the job

Would it be of interest to expose all payload parameters as well, so you can use any one you like?
E.g. if the job has repository_name parameter, it would be filled with Diaspora value, taken from the above example payload.

@xaniasd

This comment has been minimized.

Copy link
Contributor

xaniasd commented Jun 13, 2014

I started tinkering with the code and I can now create parameters based on the payload. As a proof-of-concept, I've done it with project_id, check it here:
https://github.com/xaniasd/jenkins-gitlab-hook-plugin
If you're ok with the implementation I'll create a pull request.

Passing the whole payload is not as handy as separate parameters IMO, the latter can be used in the build directly while the former needs extra parsing. I would restrict the number of parameters provided to those useful in the context of a Jenkins build. For instance, I need the project_id to use later in api calls to GitLab. If there's more input from other users, we can add more parameters.

@adamjk-dev If you need just the branch name, that's already possible. Following the instructions of the plugin, just create a string parameter (e.g. BRANCH_TO_BUILD) and make sure the same parameter is used under SCM => branches to build should be */${BRANCH_TO_BUILD}

@adamjk-dev

This comment has been minimized.

Copy link
Author

adamjk-dev commented Jun 16, 2014

Sorry, I just now saw these comments. Originally, I did want the whole payload parameter as an option, but really the use case I was looking for was getting the branch name of the check-in. So, that should cover what I need (at least for now). Perhaps xaniasd is correct, and we can just expose parameters as requested. I followed the instructions that xaniasd provided for getting the ${BRANCH_TO_BUILD} parameter, and it worked. I think I goofed it before due to a typo in the README. I can submit a pull request to fix that.
(#29)

Perhaps the README should include the complete list of substitutions that are currently supported (which parameters from the payload get substituted).

Thanks for the feedback and example for how to get the branch information I was looking for.

@elvanja

This comment has been minimized.

Copy link
Owner

elvanja commented Jun 17, 2014

Note to self:

  • expose all payload values if they are present in job parameters, nested should be somehow recognized as well, e.g. repository_name or repository.name (depending what Jenkins doesn't object to)
  • log the entire payload if not doing it already

@elvanja elvanja added the enhancement label Jun 17, 2014

@adamjk-dev

This comment has been minimized.

Copy link
Author

adamjk-dev commented Jun 17, 2014

I like it... thanks a lot. That will make this plugin much more usable and flexible according to the user's needs.

Make sure you give some examples of using other payload values. Since the other payload values won't make sense in the branch specifier in the Jenkins job. Will you be able to just replace any 'payload'-named parameter? Just try to make sure it is clear how to access each of those variables in the Jenkins job is all. I had some issues with that upon first reading the README.

@elvanja

This comment has been minimized.

Copy link
Owner

elvanja commented Jun 17, 2014

Yep, the idea would be to replace any parameter that exist in payload with related parameter from job configuration. Examples will be made, surely.

elvanja added a commit that referenced this issue Jul 13, 2014

issue #26 related
all payload data can be automatically fill project parameters
@elvanja

This comment has been minimized.

Copy link
Owner

elvanja commented Jul 15, 2014

Version 1.1.0 has this resolved. If the plugin version doesn't come up on Manage Plugins page, you can install manually from http://repo.jenkins-ci.org/releases/org/jenkins-ci/ruby-plugins/gitlab-hook/1.1.0/.

I've removed explicit project_id since it was never used in other parts of the code, only as an option to fill job parameters. But, it is still accessible because it is dynamically read from payload. Other examples are included in the readme.

@elvanja elvanja closed this Jul 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.