我有一个用于我的multibranch项目的声明性管道脚本,我想在其中读取一个文本文件并将结果存储为一个字符串变量,以供管道中的后续步骤访问.使用片段生成器我尝试做这样的事情:
filename = readFile 'output.txt'
Run Code Online (Sandbox Code Playgroud)
这filename将是我的字符串.
我在Jenkins控制台输出中出错:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 30: Expected a step @ line 30, column 5.
filename = readFile 'output.txt'
Run Code Online (Sandbox Code Playgroud)
我是否需要使用withEnv步骤将输出设置readFile为Jenkins环境变量?如果是这样,怎么样?
谢谢
groovy jenkins jenkins-plugins jenkins-pipeline multibranch-pipeline
__consuming在Sequence.swift中有一些函数(很可能是其他地方,但我还没有真正环顾四周).我知道它是某种类型的声明修饰符,但我不确定它是做什么的.
我试图在我的Jenkins文件中使用if语句进行多分支管道项目.为了这个问题,我假设我当前目录中有一个名为'scan.txt'的文本文件.使用bash命令生成文本文件
echo "False" > scan.txt
Run Code Online (Sandbox Code Playgroud)
所以唯一的内容是字符串"False"
我在我的Jenkinsfile中将一个任意环境变量设置为scan.txt的内容,如下所示:
script {
env.TEXT = readFile 'scan.txt'
}
Run Code Online (Sandbox Code Playgroud)
如果我做
echo "${env.TEXT}"
Run Code Online (Sandbox Code Playgroud)
在脚本块之外,jenkins控制台会按预期显示该步骤的False.
但是,我检查它是否等于"False"的所有尝试都失败了.我在脚本块后立即尝试了以下内容:
if (env.TEXT.equals("False")) {
//do something
}
if (env.TEXT.matches("False")) {
//do something
}
if (env.TEXT == "False") {
//do something
}
Run Code Online (Sandbox Code Playgroud)
并且它们都不起作用.所有这些条件都是布尔值false.读取文件管道步骤的文档声明它返回文件内容的字符串 https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-readfile-code-read-file-from-工作区 所以我不确定这里发生了什么.有没有人有任何见解?
谢谢
我正在关注DynamoDB python教程.此步骤显示如何基于特定密钥查询表:http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.04.html.
以下是此查询的代码:
from __future__ import print_function # Python 2/3 compatibility
import boto3
import json
import decimal
from boto3.dynamodb.conditions import Key, Attr
# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
return str(o)
return super(DecimalEncoder, self).default(o)
dynamodb = boto3.resource('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
table = dynamodb.Table('Movies')
print("Movies from 1992 - titles A-L, with genres and lead actor")
response = table.query(
ProjectionExpression="#yr, title, info.genres, info.actors[0]",
ExpressionAttributeNames={ "#yr": "year" }, # …Run Code Online (Sandbox Code Playgroud)