
Certificates custom pipeline steps
Empty email coming with no subject and nothing relevant on the body
Expired certificates with a link to CALM
///
/// Loads a list of all service keys with certificates available on an cloud foundry (CF) runtime and their respective expiration date
///
def loadCFServiceKeyCertificatesExpirationDates(String token,String cfHost)
{
def certs = [:]
try {
def serviceKeysListResponse = httpRequest acceptType: 'APPLICATION_JSON', customHeaders: [[maskValue: false, name: 'Authorization', value: token]],
ignoreSslErrors: true, validResponseCodes: '100:399, 404', timeout: 30,
url: 'https://' + cfHost + '/v2/service_keys';
if (serviceKeysListResponse.status == 404) {
//invalid Flow ID
error("Unable to list SAP CF service keys certificates expiration dates");
} else {
def serviceKeyJson = new JsonSlurper().parseText(serviceKeysListResponse.content )
// aux list is being created to prevent jenkins issues with global objects not serializable
serviceKeyJson.resources.each {
if (it.entity != null){
def serviceKeyName = it.entity.name
def certificateValue = it?.entity?.credentials?.oauth?.certificate
if(certificateValue!=null && !"".equals(certificateValue))
{
String certB64 = certificateValue.replace("-----END CERTIFICATE-----", "").replace("-----BEGIN CERTIFICATE-----", "").replaceAll("[\\n\\t ]", "").trim()
byte[] encodedCert = Base64.getDecoder().decode(certB64);
ByteArrayInputStream inputStream = new ByteArrayInputStream(encodedCert);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(inputStream);
Date certExpirydate = new SimpleDateFormat("yyyy-MM-dd").parse(cert.notAfter.toTimestamp().toString());
def subjectDN = cert.getSubjectDN().toString()
certs[serviceKeyName] = [certExpirydate:certExpirydate,subjectDN:subjectDN]
}
}
}
}
} catch (Exception e) {
error("Retrieving CF service keys:\n${e}")
}
return certs;
}
///
/// Loads a list of all certificates available on an CPI environment
///
def loadAllNonSAPCertificates(String token,String cpiHost)
{
def certs = [:]
try {
def certificateListResponse = httpRequest acceptType: 'APPLICATION_JSON', customHeaders: [[maskValue: false, name: 'Authorization', value: token]],
ignoreSslErrors: true, validResponseCodes: '100:399, 404', timeout: 30,
url: 'https://' + cpiHost + '/api/v1/KeystoreEntries';
if (certificateListResponse.status == 404) {
//invalid Flow ID
error("Unable to list SAP CPI Certificates");
} else {
def list = new JsonSlurper().parseText(certificateListResponse.content )
// aux list is being created to prevent jenkins issues with global objects not serializable
list.d.results.each {
if (it.Owner != "SAP"){
certs[it.Alias] = [certExpirydate:it.ValidNotAfter,subjectDN:it.SubjectDN] ;
}
}
}
} catch (Exception e) {
error("Retrieving CPI Certificates:\n${e}")
}
return certs;
}
def days = 45
try{
println("Checking if gitea/jenkins certificate is expired on CI/CD server")
def thresholdAlertSeconds = 24*3600*days
def result = bat "openssl x509 -checkend " + thresholdAlertSeconds + " -noout -in \"C:/WorkSpaces/Certificates/certificate.pem\""
}catch(Exception exc){
isToSendEmail = true
notifBody += '<tr><td>Jenkins/Gitea certificate</td><td> </td><td>Expires in less than '+days+' days</td></tr>'
}
if(isToSendEmail){
notifBody += '</table>'
unstable('Certificates expired or about to expire found!')
emailext mimeType: 'text/html', body: '${JELLY_SCRIPT,template="html"}' + notifBody,
from: "YOUR_CPI_TEAM@YOURDOMAIN.com",
to: 'YOUR_CPI_TEAM@YOURDOMAIN.com;YOUR_BASIS_TEAM@YOURDOMAIN.com',
subject: 'Build unstable in Jenkins for Environment ['+environment+']: $PROJECT_NAME - #$BUILD_NUMBER'
}
Example of email notification
CALM email notification update
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |