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
How to Generic .Htaccess to Prevent Hotlink
Releasing All Keys After Disabling The Keyboard in X11/Linux Using Xinput
How to Find The Version of a Compiled Kernel Module
Polling a Loop Device Through a Kernel Module
Apt-Update in Azure Nvidia Gives Publickey Error
Failed to Load Javahl Library.- Linux/Eclipse
Execute Command as a String in Bash
Sendmail/Procmail - Get Mail Sender and Mail Subject, Utf8 Encoding Issues
Javafx: Tested/Confirmed Hardware (Gpu) Acceleration on Linux
.Net Core 3.1 Deploy on Centos 7
How to Get Awk to Print Without White Space
Reset Bash History Search Position
Vagrant, Shared Folder: Take Advantage of Inotify Over Nfs
How to Extract Email Headers Extending on Multiple Lines from File
How to Measure Net Used Disk Space Change Due to Activity by a Given Process in Linux
How to Use/Learn Video4Linux2 (On Screen Display) Output APIs