下面是一个读写文件的示例,并且保证了nginx.conf中的$uri不被识别为变量
pipeline {
agent any
stages {
stage('Write and Read File') {
steps {
script {
echo "Build Stage"
def content = """
server {
listen 80;
listen [::]:80;
server_name localhost;
#gzip
#开启gzip功能
gzip on;
#开启gzip静态压缩功能
gzip_static on;
#gzip缓存大小
gzip_buffers 4 16k;
#gzip http版本
gzip_http_version 1.1;
#gzip 压缩级别 1-10
gzip_comp_level 5;
#gzip 压缩类型
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
location / {
alias /usr/share/nginx/html/;
index index.html index.htm;
try_files \$uri \$uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
"""
writeFile(
file: 'default.conf',
text: content
)
def fileContent = readFile(file: 'default.conf')
echo "${fileContent}"
}
}
}
}
}
例2(避免缩进错误):
stage('Build and Push image') {
steps {
dir("${service_name}"){
script{
def composefileContent = """
version: '3'
services:
${service_name}:
image: 192.100.30.160:9000/python/${service_name}:latest
container_name: ${service_name}
restart: always
ports:
- ${service_port}:${service_port}
volumes:
- ${publish_path}/code:/app
entrypoint: [${commandParts.split(' ').collect { "\"$it\"" }.join(', ')}]
""".stripIndent()
writeFile(file: 'docker-compose.yml', text: composefileContent)
println composefileContent
}
}
}
}
文章详细描述了一个使用pipeline进行文件读写操作的示例,特别强调了如何在Nginx.conf中正确处理$uri以避免其被识别为变量,同时展示了gzip配置选项。
2351

被折叠的 条评论
为什么被折叠?



