下面是一个读写文件的示例,并且保证了nginx.conf中的$uri不被识别为变量
pipeline {agent anystages {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}"}}}}}