Jenkins environment variable and binding domain name problem solving

Original link: https://www.iyouhun.com/post-237.html

environment variable problem

The node/npm command reports that there is no setting method

It is preferred to install node to set up a soft connection https://www.iyouhun.com/post-125.html

Then output the environment variable in the server

 echo $PATH # /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

In Jenkins system management, system configuration, set global properties, add environment variables

npx command not available

There is npx in the bin directory of the nodejs installation package, but it still reports an error

My installation directory is under /root/node-v16.13.0-linux-x64/bin/

Add execute permission to npx (if not already)

 chmod 777 npx

Create a soft link to usr/local/bin

 sudo ln -s /root/node-v16.13.0-linux-x64/bin/npx /usr/local/bin

an examination

 npx -v # 6.14.8

Use nvm to manage node versions

Sometimes the node version needs to be lowered or upgraded, you can use this tool

 wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash # 如果没装git 先装git sudo yum install git

After installation, if you are using xshell to connect to the remote host, reconnect first, otherwise you will find a prompt that the nvm command cannot be found

It may still prompt that the nvm command cannot be found, then please use the source command, as follows

 source ~/.bashrc # 如果是zsh的话,请用source ~/.zshrc

Use a specific version

 # 先安装才能使用nvm install 11.13.0 # 使用nvm use 11.13.0 # 卸载nvm uninstall 11.13.0

Jenkins bind domain name

Do the following configuration in the nginx configuration file

 # 记得在防火墙打开443端口upstream jenkins { keepalive 32; # keepalive connections server 127.0.0.1:8080; # jenkins ip and port } # Required for Jenkins websocket agents map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 443 ssl; #配置HTTPS的默认访问端口为443。 #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。 #如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。 server_name 你的域名; #需要将yourdomain.com替换成证书绑定的域名。 # root /usr/share/nginx/html; # index index.html index.htm; ssl_certificate cert/你的证书文件.pem; #需要将cert-file-name.pem替换成已上传的证书文件的名称。 ssl_certificate_key cert/你的证书密钥.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。 ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #表示使用的加密套件的类型。 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。 ssl_prefer_server_ciphers on; # pass through headers from Jenkins that Nginx considers invalid ignore_invalid_headers off; location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" { # rewrite all static files into requests to the root # Eg /static/12345678/css/something.css will become /css/something.css rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last; } location /userContent { # have nginx handle all the static requests to userContent folder # note : This is the $JENKINS_HOME dir root /var/lib/jenkins/; if (!-f $request_filename){ # this file does not exist, might be a directory or a /**view** url rewrite (.*) /$1 last; break; } sendfile on; } # 拦截Jenkins请求location /jenkins { sendfile off; proxy_pass http://jenkins; proxy_redirect default; proxy_http_version 1.1; # Required for Jenkins websocket agents proxy_set_header Connection $connection_upgrade; proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_max_temp_file_size 0; #this is the maximum upload size client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffering off; proxy_request_buffering off; # Required for HTTP CLI commands proxy_set_header Connection ""; # Clear for keepalive } }

Then set the Jenkins URL to the domain name you bind to in the Jenkins system configuration

Post my pagoda Nginx configuration

 upstream jenkins { keepalive 32; # keepalive connections server 127.0.0.1:8080; # jenkins ip and port } # Required for Jenkins websocket agents map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; listen 443 ssl http2; server_name jenkins.iyouhun.com; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/jenkins.iyouhun.com; #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则#error_page 404/404.html; #HTTP_TO_HTTPS_START if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } #HTTP_TO_HTTPS_END ssl_certificate /www/server/panel/vhost/cert/jenkins.iyouhun.com/fullchain.pem; ssl_certificate_key /www/server/panel/vhost/cert/jenkins.iyouhun.com/privkey.pem; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; add_header Strict-Transport-Security "max-age=31536000"; error_page 497 https://$host$request_uri; #SSL-END #ERROR-PAGE-START 错误页配置,可以注释、删除或修改#error_page 404 /404.html; #error_page 502 /502.html; #ERROR-PAGE-END #PHP-INFO-START PHP引用配置,可以注释或修改include enable-php-00.conf; #PHP-INFO-END #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效include /www/server/panel/vhost/rewrite/jenkins.iyouhun.com.conf; #REWRITE-END # pass through headers from Jenkins that Nginx considers invalid ignore_invalid_headers off; #禁止访问的文件或目录location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } #一键申请SSL证书验证目录相关设置location ~ \.well-known{ allow all; } location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" { # rewrite all static files into requests to the root # Eg /static/12345678/css/something.css will become /css/something.css rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last; } location /userContent { # have nginx handle all the static requests to userContent folder # note : This is the $JENKINS_HOME dir root /var/lib/jenkins/; if (!-f $request_filename){ # this file does not exist, might be a directory or a /**view** url rewrite (.*) /$1 last; break; } sendfile on; } # 拦截Jenkins请求location / { sendfile off; proxy_pass http://jenkins; proxy_redirect default; proxy_http_version 1.1; # Required for Jenkins websocket agents proxy_set_header Connection $connection_upgrade; proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_max_temp_file_size 0; #this is the maximum upload size client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffering off; proxy_request_buffering off; # Required for HTTP CLI commands proxy_set_header Connection ""; # Clear for keepalive } access_log /www/wwwlogs/jenkins.iyouhun.com.log; error_log /www/wwwlogs/jenkins.iyouhun.com.error.log; }

Pagoda panel Openssl problem

If you install Pagoda in advance and then install Jenkins and then use ssl, you may get an error

/usr/local/curl/bin/curl: error while loading shared libraries: libssl.so.1.0.0

Re-download an Openssl from the Internet to re-override the installation

Mine is in the directory /usr/local/openssl

Then remember to set a soft connection

 ln -s /usr/local/openssl/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.0 ln -s /usr/local/openssl/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.0

This article is reprinted from: https://www.iyouhun.com/post-237.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment