How to send email with condition in editable email notification - jenkins

I have job in jenkins with editable email notification post step, but email is sending every time when job is triggered. So question is how to send mail only once per day (lets say 08:00AM) and left othere job runs without email notification. Should condition be in 'pre-steps'?
thanks

I figured it out by adding such groovy code in 'pre-send' script
def mydate = new Date(System.currentTimeMillis())
Calendar cal = Calendar.getInstance();
cal.setTime(mydate);
int hour = cal.get(Calendar.HOUR_OF_DAY);
if( hour>7 && hour<9 ){
cancel=cancel}
else{
cancel=true}
So job will send email report only if it triggered in time from 7AM-9AM
cancel boolian stands for letting jenkins know if report should be send or not

Related

Want to disable & enable jenkins pipeline to achieve automation

I am working on a idea where I need to send a mail if certain conditions are met to inform the Team. The condition may continue for 30 minutes or 1 hour. But I do not want to flood the mailbox with continuous mails. As we will be scheduling the job every minute, the mails will be sent every minute. So we are trying to disable the pipeline for specific time once the mail is sent and enable it again automatically.
Thanks in advance.
I tried to put the job on sleep, but as it was scheduled to build every minute, the new jobs were initiated every minute and mails were sent.
//This is scheduled to build every minute * * * * *
`pipeline{
agent {
stages {
stage (check condition){
when
// check conditions
// if everything working fine - ok
else
// send email - this will be sent every minute. I want to avoid mailbox malfunction and just report the issue.
}
}
}
}`
Please help me with the solutions.
I used alternative: Sending below URL in the mail.
To disable the pipeline - $BUILDURL/disable to disable the pipeline.
The recipient will have to click on the link and disable the pipeline himself. This also means that the mail is acknowledged and has not gone unnoticed.
To enable the pipeline - $BUILDURL/enable. Once the issue is fixed, the recipient can enable the pipeline..
Edit:
Adding pipeline sample for reference.
pipeline{
agent any
stages {
stage ('Checkout') {
// checkout git repo
}
stage ('run job') {
// script to run the job
}
stage('email') {
when {
expression(condition to be satisfied)
}
steps {
send email
body - $Build_Url/disable to disable the job.
$Build_Url/enable to enable the job.
}
}
}

Create Microsoft Graph Api Subscription for accept/reject meeting event by attendees

In my project, I have created Rest API project to create subscription and to listen notification from Microsoft Graph API.
I want subscription for following things:
When I create meeting room event then I want to get notification if any attendees accept/reject that meeting room event.
If whole meeting event is cancelled or moves to another time slot or added any new attendees.
I was expecting all above gets covered by following code but it is not :
var subscription = new Subscription
{
ChangeType = "updated,deleted",
NotificationUrl = $"{_notificationHost}/listen",
Resource = "me/events",
ClientState = Guid.NewGuid().ToString(),
IncludeResourceData = false,
// Subscription only lasts for one hour
ExpirationDateTime = DateTimeOffset.UtcNow.AddHours(1)
};
It does not send notification when accept or reject done by attendee with 'Do not send a response'. How I can get notification for this?
I managed both scenarios :
I am getting notification for attendees's reject/approve response on my listen api : NotificationUrl = $"{_notificationHost}/listen",
If new attendess added/removed or meeting time change or meeting cancelled then also we can get notification in Listen api.

How to delete Pubnub channel history when logout from app?

In my App I'm using PubNub channels to read messages.
I get history in two status :
.PNReconnectedCategory
.PNConnectedCategory
I get history like this way:
if let lastOpenedDate = NSUserDefaults.standardUserDefaults().objectForKey(PubNubModel.lastHistoryFetchKey) as? NSDate {
let endDate = NSNumber(double:lastOpenedDate.timeIntervalSince1970)
if UserHistoryChannel != nil {
self.client?.historyForChannel(UserHistoryChannel!, start: nil, end: endDate, withCompletion: getHistoryCompletionBlock)
}
}
lastOpenedDate is a last received message date, and
in getting history I always check on it, and getting the history from this date and after it.
on logout I set this date to nil, so when the user login to the App, and Pubnub connect, when getting history this date will be the current date, and there will be no history.
But the pubnub still getting the old history!!
anyone try to clear the pubnub channels history?
Any help pleasssse?
thanks,
History API allow to specify time frame from which you want to get messages. If you will store and never reset to nil (because it will be treated as last received messages) time token (message.data.timet‌​oken) and use it as endDate with history API (as suggested by #CraigConover) - using this setup history will fetch last messages since mentioned date (endDate) inclusively (including message from which date has been taken. Using this approach allow not to pull data about which your application and user been aware since last application run. Logged new user's won't get messages (expect one) from previous session.

Received webhook notification but with empty data in servicem8

I can successfully register the webhook in serviceM8. By list the webhook subscriptions i got the result like this
[{"object":"job","callback_url":"http://ABC.XYZ/oauth/webhook/m8","fields":["active","payment_processed","uuid","company_uuid"],"active":true}]
But when i try to create new job & approve the job in servicem8, i received the notification from serviceM8 but the data in body is all empty like :
body: { '{"object":"JOB","entry":': { '"payment_processed"': '' } }
Am i missing something in webhook setup ???
Webhook notifications will not include the data record itself, only a reference to the record that has been changed/updated.
Your callback url should be receiving a JSON body similar to the example here (under Handling Webhooks):
http://developer.servicem8.com/docs/platform-services/webhooks/
Once you receive the notification, you will need to request the updated record using the supplied resource_url.

How to combine multiple notifications of the same kind

I have an iOS app that shows the user a set of different news feeds in a PageViewController. Everytime the app starts, it requests the news data from the backend for every single feed. In case it worked fine, a notification via for every single news feed is sent via NSNotificationCenter so the data can be displayed.
In case of an error, a notification for every single feed is sent as well, triggering a popup message that tells the user something went wrong. But if this happens, a popup will be shown for every news feed, up to the amount of added news feeds.
My question is, how can I combine all those error case notifications to a single one and therefore avoid having many useless and annyoing popups?
if (self.isShowingErrorDialog) {
return; // Or possibly cache to show after current one is dismissed.
} else {
[[UIAlertView ...] show];
self.showingErrorDialog = YES;
}
When you send a notification using NSNotificationCentre, you can include user info. This is basically an NSDictionary with additional information.
Why not just include the timestamp of the failed request. You can test this with some fuzziness to see if you've already put up an alert for this batch of requests.
- (void) notificationListener: (NSNotification*) notification {
static NSDate* lastAlerted = nil;
NSDate* sentDate = notification.userInfo[#"RequestDate"];
if ( lastAlerted != nil && [lastAlerted timeIntervalSince:sentDate] > FUZZY_INTERVAL) {
// post alert
// And update last Alerted
lastAlerted = sentDate;
}
}
The method you need is postNotificationWithName:Object:UserInfo:.
Gordon
I don't think you can.
Just to confirm, the notifications you're sending are Apple remote notifications and the alerts are the system alerts popped up by the message centre.
The alerts occur before you get control, as the user has to have the opportunity to ignore them, or else people would use this as a cheat to make apps run in the background and kill user's batteries.
All you can do is send a batch token in your request, and check on the back end.
Good luck

Resources