how to trigger a jenkins pipeline stage when an authorized user make a comment on github pull request? - github

I am familiar with Jenkins Pull Request Builder and I had set up a freestyle job with it to build my project based on the comment that authorized user put. (For example test in prod) in the past.
Now I am trying to use a Jenkins 2.0 with github organization plugin for one of my project.
this is the scenario:
A User is making a PR to master(or some other sensitive branch)
A test is going to get run automatically.
After the test past, an authorized user needs to go to the PR and put a comment Deploy to test environment and then a jenkinsfile that was waiting for this input needs to get trigger.
I just dont know how to do the step 3. how do I make jenkins pipeline job listen for comments in github repo pull requests? the Jenkins documentation is not really clear about the input from user part.
I read this thread answer but the documentation about the Gates approval is really limited.

I know this is super late, but here's some info for future Googlers:
I have a Github webhook that sends the event to a Lambda function that will parse the event for a specific comment string, then create an HTTP POST request for the Jenkins job, which is configured to allow builds to be triggered remotely.
So: open PR > comment on PR 'Deploy to test environment' > webhook sends to AWS APIGateway > AWS SNS topic > AWS Lambda > parse the event for comment > If comment matches, create HTTP POST > Jenkins receives request and runs job
There's a lot of documentation on this, but none of it together, so here are the resources that I used:
Regarding allowing jobs to be triggered remotely:
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
Using Github to trigger Lambda function:
https://aws.amazon.com/blogs/compute/dynamic-github-actions-with-aws-lambda/
Github API. You will want to pay particular attention to the Issues API:
https://developer.github.com/webhooks/

Related

Getting PR information in the jenkins pipeline

I am using bitbucket and jenkins as my CI/CD solution.
I am running a sanity job everytime Pull request is raised. I want to send email notification on the success or failure of the job to the owner of the pull requuest. The challenge I am facing is I am not able to get the user information for the PR in jenkins pipeline.
Anybody has solved this porblem ?
Here's a different approach to this: instead of directly emailing the author of the PR, use the Bitbucket API to write a comment on the PR (doc). Since you would already have the PR ID, it's just a matter of sending a POST request.
By default, any comments written on a Bitbucket PR automatically trigger an email to the PR author + PR reviewers so they will be getting notified via email as well.

Slack integration with Tekton missing pipeline event messages

Following the documentation here, I created a Tekton Pipeline and integrated Slack through the tool integration. I also set up an incoming webhook following the Slack API documentation. Along with configuring the webhook URL, channel, and team name, I checked the pipeline events as shown below.
I have received messages regarding the successful binding between the Tekton pipeline and Slack integration. I am also seeing other tool integrations in the Slack channel but missing the pipeline events like Pipeline start, success, and failure.
Am I missing something here?
The easiest way is by adding a definition pointing to the post to Slack task helper and the associated sample.
Additionally, I have to enable the Slack notifications setting under the Tekton pipeline.
I have documented the steps with screen captures in a blog post here

Cancel external service that runs PR status checks when PR is abandoned in Azure DevOps

We have an external service that gets triggered with every pull request to our repo in Azure DevOps, runs checks, and posts a status check back to the PR. This service is very resource heavy. Sometimes PR authors abandon the PR before the service finishes running. We are trying to find a way we can be notified of the PR being abandoned so we can also cancel orchestration and save resources. Is there a mechanism to do that?
We are trying to find a way we can be notified of the PR being abandoned so we can also cancel orchestration and save resources.
You could set the notification in Azure Devops Project Settings -> Notification -> New Subscription.
You could select the A pull request is created or updated and set the filter and target users.
When a pull request is Abandoned, the users will get the notification email.
On the other hand, you can also get the Pull Request Status via the Rest API: Pull Requests - Get Pull Request
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=6.0
Update:
You could try to create a custom workflow(e.g. Power Automate) to check the Pull Request status.
Here is an example:
Explanation:
1.The Recurrence action is set 10 minutes interval(you could set the suitable interval ). Then the flow will execute every 10 minutes to check the pull request status.
2.The Send Http Request to Azure Devops action is used to run the API above to get the Pull Request status.
3.The Condition action is used to compare the response and the value.

Integrate Cypress tests into Azure Devops Pull Request

I have been reading the Azure Devops docs and I am completely confused by them. All I want to is something very simple (simple with Github Actions in Github anyway) where
A developer creates a PR.
As the PR is created Azure runs all the associated Cypress tests
If any fail then the notes at the top of the PR indicate this. For example just next to the bit where it says 'there are merge conflicts'
We had this working in Github, but I can't figure it out here.
Thanks
There is no extension like "Cypress GitHub app" in azure devops, so it is impossible to achieve exactly the same function as in github pull request.
As a workaround , you can try to add status policy.
Using status alone, details from an external service can be provided
to users within the PR experience. Sometimes, sharing information
about a PR is all that is necessary, but in other cases PRs should be
blocked from merging until requirements are met. Like the in-box
policies, the Status policy provides a way for external services to
block PR completion until requirements are met. If the policy is
required, it must pass in order to complete the pull request. If the
policy is optional, it is informational only, and a status of
succeeded is not required in order to complete the pull request.
External services can use the PR Status API to post detailed status to your PRs. The branch policy for external services brings the ability for those 3rd party services to participate in the PR workflow and establish policy requirements. This article guides you through the process of configuring a branch policy for a service that is posting PR status.
In addition, here is a ticket about how to create required pull request status check, you can refer to it.

Concourse Webhook to Git

Environment:
BitBucket
Concourse 3.14.0
Wondering is it possible to configure Concourse pipeline with Git webhook which will check if new commit has happened and it would trigger a pipeline build based on that trigger? I looked at https://concourse-ci.org/resources.html#resource-webhook-token, but it does not tell me how to get a webhook token from Concourse and if it does support what I am asking.
Any feedback is very much appreciated.
Concourse resources usually pull any new versions every minute or so. Whenever this frequency doesn't suit your needs, you can modify it with the check_every resource property. But values lower that 1m (one minute) are typically considered aggressive. Github implements quotas for API calls and when you have many pipelines, you don't want them to fail because you've hit some quota limits.
In case you want Concourse to immediately react on published new versions for the pipeline resources, you need to reverse the pattern. Instead of Concourse pulling any new versions at some defined frequency, you start pushing the information to Concourse that some new versions are to be pulled. This reversed “push” pattern involves triggering “resource checks” whenever new versions are created on the resource.
Trigger immediate resource checks
Every Concourse resource can enable a resource-check triggering URL with the webhook_token resource property. This URL includes the webhook_token secret in its query string, and is supposed to receive a mere POST HTTP request.
With Github repositories, you can POST to this URL with a Github workflow, relying on a standard Github action from the marketplace (recommended, first choice), or a Github webhook (second choice).
Using a Github workflow
You need to commit and push a YAML file in the .github/workflows folder of your Github repository, in order to define your workflow. Refer to the documentation of the “Trigger Concourse resource-check” action for detailed examples. It's very easy, as only five simple inputs need to be configured.
Using a Github webhook
With this alternative, you can manually setup a Github webhook in your repository. The URL depends on the resource for which an immediate check is to be triggered, so you can't set it up at your Github organization level. The webhook_token secret in appended in clear-text to the URL set up for the webhook, and can't be stored as a Github secret. Github webhook don't support fetching any Github secret.
And in case you're bored of manually set up webhooks, automated setup is possible with the github-webhook resource. You can even trigger the webhook recreation whenever the webhook_token secret changes in Credhub, with the help of the Credhub resource. I've done some working code implementing this idea, see those example jobs and those example resource definitions.
But I definitely recommend using a Github workflow with the “Trigger Concourse resource-check” action as a first choice.
I think you are looking for this resource - https://github.com/concourse/git-resource
It automatically checks for any new commit in your git repository and you can run other jobs based on that.
Example pipeline.yml:
resources:
- name: git-repo
type: git
source:
uri: git#github.com:concourse/git-resource.git
branch: master
private_key: {{GIT_KEY}}
jobs:
- name: run-on-new-commit
- get: git-repo
trigger: true
- task: do-something-else