#!groovy
def parse_log(){ 
	script {
		sh(script: 'sed \'/ha/d\' /tmp/success.log > /tmp/new.log',returnStdout:true).trim()
		return readFile("/tmp/new.log")
	}
}

def sendMessage(message){
	def encode = URLEncoder.encode(message,"UTF-8")
	withCredentials([string(credentialsId: 'TGBot', variable: 'SECRET')]) {
	responce = httpRequest(contentType: 'APPLICATION_JSON',
		httpMode: 'GET',
		url: "https://api.telegram.org/bot$SECRET/sendMessage?text=$encode&chat_id=-1001282104904&disable_web_page_preview=true",
		validResponceCodes: '200')
		return responce
	}
}

pipeline {
   agent any
   environment{
   		LOG = parse_log()
   }
   stages {
      stage('Hello') {
         steps {
            sendMessage(parse_log())
         }
      }
   }
}