Forum Discussion
Try global variable currentBuild, E.G. currentBuild.rawBuild.getLog(100) get last 100 line of the log
Bonibom Is that something I can enter in my pipeline script? but how to know if error code is -1.
I want this log to verify the error code before sending the emails.
- Bonibom2 years agoContributor
Yes, it is global variable and you can use that within the script. Another way you can get the log from a particular build that your pipeline starts
bRun = build job: 'SomeJobStartingTestComplete', parameters: [ ..... bRun.getRawBuild().getLog(100)
Then you can read the log line by line, E.G.
List<String> log = bRun.getRawBuild().getLog(100) for (String line : log) { if (line.contains("Test runner exit code: -1") { // Any action if exit code is -1 .... } }
- tvklovesu2 years agoFrequent Contributor
Thanks Bonibom, for your reply. I have updated my script but still I am getting the following error.
Script in pipeline:
pipeline{
agent {label "windows"}
stages {
stage('Test complete'){
steps {
git credentialsId: 'GitHub-RAVEn', url: 'https://github.com/smoke-tests.git', branch: 'master'
withVault(configuration: [timeout: 60, vaultUrl: 'https://vault.com'],
vaultSecrets: [[engineVersion: 1, path: 'secret//testing',
secretValues: [[envVar: 'USERNAME', vaultKey: 'username'], [envVar: 'PASSWORD', vaultKey: 'password']]]]) {
testcompletetest commandLineArguments: "/run /SilentMode /psv:env=prod /psv:ADFSusername=${USERNAME} /psv:ADFSpassword=${PASSWORD}", generateMHT: true, launchType: 'lcProject', project: 'CORE_Prod_Smoke', suite: 'Prod_SmokeTest.pjs'
}
}
}
stage('Checking log'){
steps{
script{
List<String> log= currentBuild.rawBuild.getLog(100).contains("exit code: 0")
for (String line : log)
{
if (line.contains("Test runner exit code: 0"))
{
echo 'aborted'
emailext (
subject: "Core application Failed to login in Prod",
body: "Core application seems to be failed to login in Prod. Please click the link to access the test results for more details \n" + env.BUILD_URL+"TestComplete/",
to: 'vinod.k.tanguturi@associates.com',
from: "donotreply@cloudbees.com")
}
}
}
}
}
}Error in console
[GitHub Checks] GitHub check (name: Jenkins, status: COMPLETED) has been published. org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.model.Run getLog int at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:265) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:161) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17) at WorkflowScript.run(WorkflowScript:18
- Bonibom2 years agoContributor
You may need to add or approve your signatures in Manage Jenkins -> In-process Script Approval
Related Content
- 3 years ago
Recent Discussions
- 10 hours ago