ini 詹金斯新贵剧本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ini 詹金斯新贵剧本相关的知识,希望对你有一定的参考价值。

#upstart script for a jenkins swarm agent
description "upstart script for jenkins-master"

start on started networking

stop on runlevel [016]

# respawn the job up to 10 times within a 10 second period.
# If the job exceeds these values, it will be stopped and
# marked as failed.
respawn
respawn limit 5 10

#setgid jenkins
#setuid jenkins

console output

pre-start script
    logger -is -t "$UPSTART_JOB" "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting"
end script

script
MASTER=jobs-jenkins-master-ha

CATALINA_HOME=/home/jenkins/vendor/tomcat6
CATALINA_BASE=/home/jenkins
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"
TOMCAT6_SECURITY=no
JENKINS_HOME=/var/lib/jenkins
TOMCAT6_USER=jenkins
TOMCAT6_GROUP=jenkins
#JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64
JAVA_HOME=/home/jenkins/vendor/jdk8/jre
JRE_HOME=/home/jenkins/vendor/jdk8/jre
PATH="$JRE_HOME/bin:$PATH"

if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="-Djava.awt.headless=true -Xmx6g"
fi
#JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:MaxPermSize=1024m"
#JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:MaxPermSize=4096m"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"

export CATALINA_HOME CATALINA_BASE TOMCAT6_SECURITY TOMCAT6_USER TOMCAT6_GROUP
export JAVA_HOME JAVA_OPTS JRE_HOME
export JENKINS_HOME PATH
#exec $CATALINA_SH start
exec su -s /bin/sh -c 'exec "$0" "$@"' jenkins -- /home/jenkins/bin/jenkins.sh run
end script


pre-stop script
  logger -is -t "$UPSTART_JOB" "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping"
end script
EOF

詹金斯:对于每个循环问题

我正在使用Jenkins来触发Ansible剧本。我想传递一系列计算机名称,以便Ansible剧本能够触发剧本并逐一对机器进行成像。

为了做到这一点,我相信我需要一个foreach循环。

我在groovy / Jenkins方面没什么技巧,遇到了一个问题。

error = "Expected a symbol @ line..."这指的是HOSTS.each {item - >

有人可以帮助我吗?我的脚本如下(我已经编辑了一些私人数据)

pipeline {
    agent any
    // every day
    triggers {
        cron('H 7 * * *')
    }

    environment {
          HOSTS = ['node1','node2']
    }

stages {

    stage('MachineDB Scheduler') {
            steps {
                HOSTS.each { item -> // review
                    HOSTNAME = ${item} // review
                    ansibuildPlaybookperf(
                        sshUser: env.USER,
                        vaultUser: env.USER,
                        server: "$SERVER",
                        dir: "$HOMEDIR/$BUILD_TAG",
                        playbook: "$PLAYBOOK",
                        extras: "--vault-password-file passmgr.sh",
                        extraVars: "$VARS_JENKINS"
                    )
                }
            }
        }
    }
}
答案

我对ansible并不是很了解,但也许这会有所帮助。此管道显示PC的列表。在声明性管道中,我调用了一个在管道之后定义的groovy函数。在这个函数中,我浏览列表并通过每个PC名称。

def list = [
        'PCNAME1',
        'PCNAME2',
        'PCNAME3'
]

pipeline {
    agent any

    stages {
        stage('Loop through PCs') {
            steps {
                loopPC(list)
            }
        }
    }
}

def loopPC(list){
    list.each {
        println "Computer ${it}"
    }
}

OUTPUT:

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Loop through PCs)
[Pipeline] echo
Computer PCNAME1
[Pipeline] echo
Computer PCNAME2
[Pipeline] echo
Computer PCNAME3
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

您还可以在声明性管道中使用脚本块立即执行脚本。它不太干净,但在开始时可能更容易并使其工作(并且更接近您的尝试):

def list = [
        'PCNAME1',
        'PCNAME2',
        'PCNAME3'
]

pipeline {
    agent any

    stages {
        stage('Loop through PCs') {
            steps {
                script {
                    list.each {
                    println "Computer ${it}"
                    }
                }
            }
        }
    }
}

以上是关于ini 詹金斯新贵剧本的主要内容,如果未能解决你的问题,请参考以下文章

詹金斯:对于每个循环问题

ini 彪马新贵

ini 新贵示例脚本

詹金斯工作的 Ansible 提示

ini 堡垒剧本

ini RPiv3 2017最新剧本。修复/etc/resolv.conf以获取正确的DNS名称服务器+ IPv6