-
-
Save O5ten/d201d57cde57934d97d8e23a01760ebd to your computer and use it in GitHub Desktop.
Födelsedagsbotten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@groovy.transform.Field | |
def people = [ | |
[ | |
name: 'Jocke', date: [ | |
year: 1986, | |
month: 11, | |
day: 27 | |
] | |
], | |
[ | |
name: 'Micke', date: [ | |
year: 1987, | |
month: 11, | |
day: 16 | |
] | |
], | |
[ | |
name: 'Sara', date: [ | |
year: 1987, | |
month: 3, | |
day: 21 | |
] | |
], | |
[ | |
name: 'Gustav', date: [ | |
year: 1988, | |
month: 6, | |
day: 22 | |
] | |
], | |
[ | |
name: 'Alex', date: [ | |
year: 1986, | |
month: 10, | |
day: 17 | |
] | |
], | |
[ | |
name: 'David', date: [ | |
year: 1987, | |
month: 7, | |
day: 1 | |
] | |
], | |
[ | |
name: 'Mattias', date: [ | |
year: 1986, | |
month: 6, | |
day: 27 | |
] | |
], | |
[ | |
name: 'Donny', date: [ | |
year: 1987, | |
month: 4, | |
day: 27 | |
] | |
], | |
[ | |
name: 'Patrik', date: [ | |
year: 1988, | |
month: 1, | |
day: 18 | |
] | |
], | |
[ | |
name: 'Osquar', date: [ | |
year: 1988, | |
month: 11, | |
day: 16 | |
] | |
], | |
[ | |
name: 'Henrik', date: [ | |
year: 1982, | |
month: 9, | |
day: 14 | |
] | |
], | |
[ | |
name: 'Pavel', date: [ | |
year: 1987, | |
month: 11, | |
day: 27 | |
] | |
] | |
] | |
@NonCPS | |
def getDate(){ | |
def date = java.time.Instant.now().toString().tokenize('T')[0].tokenize('-') | |
return [year: date[0] as int, month: date[1] as int, day: date[2] as int] | |
} | |
def getBirthdayPerson(date){ | |
def potentialPerson = people.find{p -> p.date.month == date.month && p.date.day == date.day} | |
if(potentialPerson) { | |
println "$potentialPerson.date.year && $date.year" | |
potentialPerson.age = date.year - potentialPerson.date.year | |
} | |
return potentialPerson | |
} | |
pipeline { | |
agent { | |
label 'linux' | |
} | |
triggers { | |
cron '0 7 * * *' | |
} | |
environment { | |
MICKE='7cnjxi1g6bdi8ffmo6tz3mc3co' | |
PI_DELAR='e3pb6xqy1b87tfuze691at7ajo' | |
} | |
stages { | |
stage('Birthday Wish!') { | |
steps { | |
script { | |
def date = getDate() | |
def person = getBirthdayPerson(date); | |
if(person) { | |
withCredentials([string(credentialsId: 'BIRTHDAY_BOT_MATTERMOST', variable: 'BOT_BEARER_TOKEN')]) { | |
sh """curl -H "Authorization: Bearer $BOT_BEARER_TOKEN" https://mattermost.05ten.se/api/v4/posts -d '{"channel_id": "$PI_DELAR", "message": "@all Grattis på födelsedagen **${person.name}** som fyller **${person.age}** år idag!"}'""" | |
} | |
} else { | |
echo "Nobody has a birthday today. :'(" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment