GitHub Actions - Notifications for scheduled cron jobs - scheduled-tasks

Is it possible to get email or Slack notifications for Workflow scheduled Cron jobs?

You could use a custom app in Slack, with an incoming webhook, and add a step to your workflow to post a JSON message to that webhook URL.
In Slack
Start by creating a new Slack app, at https://api.slack.com/apps?new_app=1
Activate the Incoming Webhooks feature
Add a new webhook URL, which may need to be approved by an administrator of your workspace
Add a new webhook to your workspace, selecting a channel for the post to be sent to
Copy the webhook URL
In GitHub
Go to your repository settings, and add an Actions secret named SLACK_WEBHOOK_URL with the value being the URL copied from Slack
In the Actions workflow
Add a new step to your workflow:
-
name: Notify Slack
run: |
curl -X POST -H 'Content-type: application/json' --data \
'{"username": "GitHub Actions robot", "icon_emoji": ":robot_face:", "text": "GitHub Actions workflow completed"}' \
${SLACK_WEBHOOK_URL}

Related

GitHub WebHook call Action on another GitHub repository

Want to trigger a GitHub Action (Repository B) from another GitHub Repository (A) via WebHook.
So I try to configuring the WebHook on repository A but I can not specify the Authorization Header that is needed by GitHub Repository B.
Is this possible at all via WebHooks?
Both Repositories belong to the same Organization.
via WebHook
That means repo A WebHook URL is called, and your local endpoint (which listen to the wayhook payload) would need to receive a parameter representing the URL/name of repoB, which it then could curl -X POST in order to trigger its workflow (assuming you have the right token allowed to run API on repoB, in Authorization: bearer <token>).
Considering a webhook JSON payload for a push event include commit(s) message, I would push on repoA a commit with, in its message, the name or URL of repoB.
Your local webhook listener can then extract repoB, and tribber its workflow.

Trigger GitHub Actions from Jenkins Pipeline using API/Actions Pluginfor Jenkins

I want to trigger the GitHub Actions using Jenkins Pipeline or Jenkins Job and send some build parameters as input for the GitHub Actions. I am doing this since there is no option of dropdown list for the GitHub Action Input parameters.
This is only half a solution. But there is an option to specify an input params list for GitHub actions.
See workflow_dispatch event type on GitHub actions. The current url is here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch (If this stops working just google workflow_dispatch)
The other half (Jenkins triggering a GHA build), I am actually searching for myself too! I can find ones working in reverse. GHA triggering jenkins.
We can trigger Github action with rest api (POST) or curl requests.
All you need to do create with workflow with dispatch trigger (repository_dispatch or workflow_dispatch)
on:
workflow_dispatch:
inputs:
InputKey:
type: string
required: true
next trigger this workflow by one of the below methods
1.
POST https://api.github.com/repos///dispatches
Authorization: Bearer
{"event_type": "hello"}
curl --request POST
--url 'https://api.github.com/repos///dispatches'
--header 'authorization: Bearer '
--data '{"event_type": "hello"}'
Also specify the inputs in requests with --data '{"event_type": "<workflow name>","client_payload":{"<input_key>":"<input_value>"}}'
All you need to do now is put this request in your job (scripted pipeline is preferred) with appropriate values.

How we can disable merge of a pull request in github if any check fails in the CI job

We have a Jenkins CI job, where we will run a job when a pull request is raised. If that job fails in any case, we should not allow the user to merge the pull request. Is there any way we can do using github actions?
You could:
enable to branch protection policy "Require status checks to pass before merging"
Follow the "Creating CI tests with the Checks API" guide, which does not require a GitHub Action, and can create "Check runs and requested actions".
Using checks (as I mentioned here) would be a good way to prevent any merge while the PR has any check with an associated "failed" status.
The OP Ramanichandran confirms in the comments it is working:
For each failure stage in jenkins, we call this github api
sh('curl "https://api.github.com/repos/reponame/statuses/$GIT_COMMIT?access_token=xxx" \
-H "Content-Type: application/json" \
-X POST \
-d "{\\\"state\\\": \\\"failure\\\", \\\"target_url\\\": \\\"https://jenkinsurl/job/foldername/job/jobname/$BUILD_NUMBER/console\\\", \\\"description\\\": \\\"Jenkins-CI-pre-merge-job-sonarscan-failure\\\", \\\"context\\\": \\\"Jenkins-CI-pre-merge-job-sonarscan-failure\\\"}"') } –

How gitub webhooks works?

How the github webhooks works, and how would it know which build needs to trigger based on the events.
I have an public git repository and in which have configured the jenkins webhooks which triggers build on the every push event.
Payload URL: http:///github-webhook/
Content Type: www-form-urlencoded
Event: Push
How the Payload URL identifies the right build job to trigger?
You can using "Generic Webhook Trigger" or "Trigger Builds Remotely" Plugin and specify token on your jenkins job. Pass your jenkins server url (with token you have specified) on github webhook payload url

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

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/