Expect Utility Is Not Working When Executing from Jenkins

jq - not working as expected in Jenkins shell script

test/0 is for testing if a string matches a particular regular expression, which is not available in jq 1.3 (as mentioned in the comments). contains/1 could be used in this case.

del(.[] | select(.artifact_location | contains("foo")))

I would rather approach this as filtering out the objects, rather than deleting them. Select objects that does not contain "foo".

map(select(.artifact_location | contains("foo") | not))

Jenkins build failing without updating Xray with the failed status

Your case should be easy to fix. Behave utility returns exit code 1 if tests fails..

Just add this to the end of your behave command || /usr/bin/true (please make sure of the path of the "true" command).
This will make your command to always return true even if some problems exist with behave.

So your overall command should be something like:

/var/lib/jenkins/.pyenv/shims/behave -f cucumber -o storetarget-bdd/reporting/cucumber.json --junit --format=json -o target/behave.json --junit ./features/PROD-003.feature || /usr/bin/true

Jenkinsfile declarative pipeline sh commands not working

You will need to escape $id to \$id otherwise Jenkins thinks you are trying to use a Groovy var rather than a shell var.

i.e.

pipeline {
agent { label 'master' }
stages {
stage("Create container") {
steps {
script {
SEQ = sh(returnStdout: true, script: 'seq 1 9').trim()
sh "echo '${SEQ}'"
sh """
for id in '{$SEQ}'
do
echo \$id
done
"""
}
}
}
}
}

Will give you

  [Pipeline] {
[Pipeline] stage
[Pipeline] { (Create container)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ seq 1 9
[Pipeline] sh
+ echo 1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
[Pipeline] sh
+ echo {1 2 3 4 5 6 7 8 9}
{1 2 3 4 5 6 7 8 9}
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

The other issue you may have in this is that seq adds a newline after every number it prints so your for loop wont work as that expects space separated values rather than new line so that would need fixing in for your example to work as you expect.

Jenkins Pipeline: Executing a shell script

If the command 'sh backup_grafana.sh' fails to execute when it actually should have successfully executed, here are two possible solutions.

1) Maybe you need a dot slash in front of those executable commands to tell your shell where they are. if they are not in your $PATH, you need to tell your shell that they can be found in the current directory. here's the fixed Jenkinsfile with four non-whitespace characters added:

pipeline {
agent {
node {
label 'jenkins-slave-python2.7'
}
}
stages {
stage('Take the grafana backup') {
steps {
sh './backup_grafana.sh'
}
}
stage('Push to the grafana-backup submodule repository') {
steps {
sh './gitPush.sh'
}
}
}
}

2) Check whether you have declared your file as a bash or sh script by declaring one of the following as the first line in your script:

#!/bin/bash 

or

#!/bin/sh

Jenkins pipeline error in handling json file

I've solved this myself with the help of "Matt Schuchard"'s below answer. I'm not sure whether this is the only way to solve but this worked for me.

pipeline {
agent any
stages {
stage('Json-Build') {
steps {
script {
def envname = readJSON file: "${env.WORKSPACE}/manifest.json"
element1 = "${envname.dev}"
echo element1
}
}
}
}
}


Related Topics



Leave a reply



Submit