防止从Jenkinsfile内部调用的bash脚本被杀死

时间:2019-05-13 02:23:51

标签: bash jenkins jenkins-pipeline jenkins-groovy

我正在尝试从詹金斯工作的侧面执行bash脚本。

这是jenkinsfile的相关部分:

pipeline {
    agent any
    options {
        disableConcurrentBuilds()
    }
    stages {
        stage('Test') {
            steps {
                script {
                    withEnv([
                            'ENVIRONMENT=TEST',
                            "COMPOSE_PROJECT_NAME=TEST_${BRANCH_NAME}",
                            'POSTGRES_DB_USER=postgres',
                            'POSTGRES_DB_DBNAME=postgres',
                    ]) {
            sh "ls -la"
            sh "./lineEndings.sh"

触发作业时,这是相关的输出

+ ls -la
total 284
drwxr-xr-x 8 jenkins jenkins   4096 May 12 00:37 .
drwxr-xr-x 4 jenkins jenkins  24576 May 12 00:37 ..
-rwxr-xr-x 1 jenkins jenkins    993 May 12 00:37 lineEndings.sh
[Pipeline] sh
Killed
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
Stage "Deploy" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

ERROR: script returned exit code 137
Finished: FAILURE

正在执行的脚本如下

#!/bin/bash

traverse_files(){
    #echo "layer="$1
    local outter_files
    mapfile -t outter_files < <( ls | tr '\n' '\n' )
    local index
    for (( index=0; index < ${#outter_files[@]}; index++ ))
    do
        #echo ${outter_files[$index]}
        if [ -d "${outter_files[$index]}" ]
        then
            #echo -e "\tits a directory"
            dir=$(pwd)
            #echo "going to ${outter_files[$index]} from $dir"
            cd ${outter_files[$index]}
            traverse_files $(expr $1 + 1)
            if [ $? -eq 1 ]; then
                return 1
            fi
            #echo "going back to $dir"
            cd $dir
            #echo "back at ${outter_files[$index]}"

        else
            fileType=$(file -i ${outter_files[$index]} | cut -d' ' -f2)
            if [ "$fileType" == "text/x-python;" ] || [ "$fileType" == "text/plain;" ]; then
                result=$(dos2unix < ${outter_files[$index]} | cmp - ${outter_files[$index]})
                if [ "$result" != "" ]; then
                    echo ${outter_files[$index]} is not using linux line endings!
                    return 1
                fi
            fi
            #echo -e "\tits a regular file"
        fi

    done
}
traverse_files 1

我对仅包含以下内容的脚本进行了一些额外的调查

#!/bin/bash
var=1

while [ $var -lt 200 ]
do
        date
        # echo alive $var
        # var=$(expr $var + 1)
done

它结束了

modernNeo@server:~$ sudo -u jenkins /home/modernNeo/command.sh 
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Sun May 12 23:52:59 UTC 2019
Killed

我不知道是什么杀死了这些脚本,以及如何让它们在合理的时间内运行?

0 个答案:

没有答案