我试图建立一个管道,以修改卡夫卡的主题。部分步骤包括获取主题的当前分区数,以确定是否可以更新。出于某种原因,jenkins不喜欢我在脚本中使用变量。我在--topic ${TOPIC}
上有个错误。这个变量被{}正确地括起来了,所以我不明白发生了什么。
给出错误:
WorkflowScript: 32: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 32, column 36.
--topic ${TOPIC} | head -1)
管道片段:
script {
sh """
if [ -n "\$(printf '%s\n' ${NUM_PARTITIONS} | sed 's/[0-9]//g')" ]; then
echo 'Num partitions is not numeric'
exit 1
fi
"""
sh """
desc=\$(kafka-topics.sh \
--bootstrap-server ${KAFKA_SERVERS} \
--command-config sasl.properties \
--describe \
--topic ${TOPIC} | head -1)
if [ \$? -ne 0 ]; then
echo 'describe failed'
exit 1
fi
np=\$(echo desc | gawk 'match($0, /PartitionCount:\s*([[:digit:]]*)\s*/, a) {print a[1]}')
if [ ${NUM_PARTITIONS} -le np ]; then
echo 'num partitions <= configured partitions. alter skipped'
else
kafka-topics.sh \
--bootstrap-server ${KAFKA_SERVERS} \
--command-config sasl.properties \
--alter \
--topic ${TOPIC} \
--partitions ${NUM_PARTITIONS}
fi
"""
}
发布于 2022-09-08 19:53:12
开始起作用了。奇怪的逃避规则..。
script {
sh """
if [ -n "\$(printf '%s\n' ${NUM_PARTITIONS} | sed 's/[0-9]//g')" ]; then
echo 'Num partitions is not numeric'
exit 1
fi
if [ -n "\$(printf '%s\n' ${RETENTION} | sed 's/[0-9]//g')" ]; then
echo 'Retention is not numeric'
exit 1
fi
"""
sh """
desc=\$(${KAFKA_SCRIPTS_LOC}/kafka-topics.sh \
--bootstrap-server ${KAFKA_SERVERS} \
--command-config ${SASL_LOC} \
--describe \
--topic $TOPIC)
if [ \$? -ne 0 ]; then
echo 'describe failed'
exit 1
fi
np=\$(echo \${desc} | head -1 | gawk 'match(\$0, /PartitionCount:\\s*([[:digit:]]*)\\s*/, a) {print a[1]}')
if [ ${NUM_PARTITIONS} -le \${np} ]; then
echo 'num partitions <= configured partitions. alter skipped'
else
${KAFKA_SCRIPTS_LOC}/kafka-topics.sh \
--bootstrap-server ${KAFKA_SERVERS} \
--command-config ${SASL_LOC} \
--alter \
--topic ${TOPIC} \
--partitions ${NUM_PARTITIONS}
fi
"""
}
https://stackoverflow.com/questions/73653066
复制相似问题