首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >詹金斯管线条的问题

詹金斯管线条的问题
EN

Stack Overflow用户
提问于 2022-09-08 17:33:32
回答 1查看 17关注 0票数 -1

我试图建立一个管道,以修改卡夫卡的主题。部分步骤包括获取主题的当前分区数,以确定是否可以更新。出于某种原因,jenkins不喜欢我在脚本中使用变量。我在--topic ${TOPIC}上有个错误。这个变量被{}正确地括起来了,所以我不明白发生了什么。

给出错误:

代码语言:javascript
运行
复制
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)

管道片段:

代码语言:javascript
运行
复制
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
                    """
}
EN

回答 1

Stack Overflow用户

发布于 2022-09-08 19:53:12

开始起作用了。奇怪的逃避规则..。

代码语言:javascript
运行
复制
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
                    """
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73653066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档