5.Jenkins入门基础使用补充说明与相关问题总结

2024-08-28 03:08

本文主要是介绍5.Jenkins入门基础使用补充说明与相关问题总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录一览:

  • 0x05 补充说明

    • (1) 内置环境变量

    • (2) Jenkins 管理员密码忘记重置

    • (3) Jenkins 升级迁移

  • 0x06 入坑&出坑


WeiyiGeek Blog - 为了能到远方,脚下的每一步都不能少。

Tips : 本文章来源 Blog 站点或者 WeiyiGeek 公众账号 (技术交流、友链交换请邮我哟), 原文地址: 5.Jenkins入门基础使用补充说明与相关问题总结

  • 微信公众号-WeiyiGeek # 精华文章发布地址(及时发布)
  • 首页-https://weiyigeek.top # 采用cloudflare CDN 国内有时访问较慢
  • https://weiyigeek.gitee.io # 国内访问快但可能会有更新不及时的情况

WeiyiGeek-公众账号


0x05 补充说明

(1) 内置环境变量

PS : Jenkins 默认的环境变量列表 http://jenkins.weiyigeek.top:8080/env-vars.html/

BUILD_NUMBER #The current build number, such as "153"
BUILD_ID# The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds
BUILD_DISPLAY_NAME# The display name of the current build, which is something like "#153" by default.
JOB_NAME# Name of the project of this build, such as "foo" or "foo/bar".
JOB_BASE_NAME# Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".
BUILD_TAG# String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.
EXECUTOR_NUMBER# The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
NODE_NAME# Name of the agent if the build is on an agent, or "master" if run on master
NODE_LABELS# Whitespace-separated list of labels that the node is assigned.
WORKSPACE# The absolute path of the directory assigned to the build as a workspace.
WORKSPACE_TMP# A temporary directory near the workspace that will not be browsable and will not interfere with SCM checkouts. May not initially exist, so be sure to create the directory as needed (e.g., mkdir -p on Linux). Not defined when the regular workspace is a drive root.
JENKINS_HOME# The absolute path of the directory assigned on the master node for Jenkins to store data.
JENKINS_URL# Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)
BUILD_URL# Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)
JOB_URL# Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)
GIT_COMMIT# The commit hash being checked out.
GIT_PREVIOUS_COMMIT# The hash of the commit last built on this branch, if any.
GIT_PREVIOUS_SUCCESSFUL_COMMIT# The hash of the commit last successfully built on this branch, if any.
GIT_BRANCH# The remote branch name, if any.
GIT_LOCAL_BRANCH# The local branch name being checked out, if applicable.
GIT_CHECKOUT_DIR# The directory that the repository will be checked out to. This contains the value set in Checkout to a sub-directory, if used.
GIT_URL# The remote URL. If there are multiple, will be GIT_URL_1, GIT_URL_2, etc.
GIT_COMMITTER_NAME# The configured Git committer name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page.
GIT_AUTHOR_NAME# The configured Git author name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page.
GIT_COMMITTER_EMAIL# The configured Git committer email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.
GIT_AUTHOR_EMAIL# The configured Git author email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.

测试环境变量:

#!/bin/bash
echo BUILD_NUMBER: ${BUILD_NUMBER }echo BUILD_ID: ${BUILD_ID}echo BUILD_DISPLAY_NAME: $BUILD_DISPLAY_NAME:echo JOB_NAME: $JOB_NAMEecho JOB_BASE_NAME: $JOB_BASE_NAMEecho BUILD_TAG: $BUILD_TAGecho EXECUTOR_NUMBER: $EXECUTOR_NUMBERecho NODE_NAME: $NODE_NAMEecho NODE_LABELS: $NODE_LABELSecho WORKSPACE: $WORKSPACEecho WORKSPACE_TMP: $WORKSPACE_TMPecho JENKINS_HOME: $JENKINS_HOMEecho JENKINS_URL: $JENKINS_URLecho BUILD_URL: $BUILD_URLecho JOB_URL: $JOB_URLecho GIT_COMMIT: $GIT_COMMITecho GIT_PREVIOUS_COMMIT: $GIT_PREVIOUS_COMMITecho GIT_PREVIOUS_SUCCESSFUL_COMMIT: $GIT_PREVIOUS_SUCCESSFUL_COMMITecho GIT_BRANCH: $GIT_BRANCHecho GIT_LOCAL_BRANCH: $GIT_LOCAL_BRANCHecho GIT_CHECKOUT_DIR: $GIT_CHECKOUT_DIRecho GIT_URL: $GIT_URLecho GIT_COMMITTER_NAME: $GIT_COMMITTER_NAMEecho GIT_AUTHOR_NAME: $GIT_AUTHOR_NAMEecho GIT_COMMITTER_EMAIL: $GIT_COMMITTER_EMAILecho GIT_AUTHOR_EMAIL: $GIT_AUTHOR_EMAIL

测试结果:

+ /bin/bash /tmp/script/env.sh
BUILD_NUMBER: 22
BUILD_ID: 22
BUILD_DISPLAY_NAME: #22:
JOB_NAME: Maven-HelloWorld
JOB_BASE_NAME: Maven-HelloWorld
BUILD_TAG: jenkins-Maven-HelloWorld-22
EXECUTOR_NUMBER: 0
NODE_NAME: master
NODE_LABELS: master
WORKSPACE: /var/lib/jenkins/workspace/Maven-HelloWorld
WORKSPACE_TMP: /var/lib/jenkins/workspace/Maven-HelloWorld@tmp
JENKINS_HOME: /var/lib/jenkins
JENKINS_URL: http://jenkins.weiyigeek.top:8080/
BUILD_URL: http://jenkins.weiyigeek.top:8080/job/Maven-HelloWorld/22/
JOB_URL: http://jenkins.weiyigeek.top:8080/job/Maven-HelloWorld/
GIT_COMMIT: 0f50b10b09c160a86972178d94ca1f0a704dd767
GIT_PREVIOUS_COMMIT: 0f50b10b09c160a86972178d94ca1f0a704dd767
GIT_PREVIOUS_SUCCESSFUL_COMMIT: 0f50b10b09c160a86972178d94ca1f0a704dd767
GIT_BRANCH: v1.7
GIT_URL: git@gitlab.weiyigeek.top:ci-cd/java-maven.git
GIT_AUTHOR_NAME:
GIT_AUTHOR_EMAIL:
GIT_COMMITTER_NAME:
GIT_COMMITTER_EMAIL:
GIT_LOCAL_BRANCH:
GIT_CHECKOUT_DIR:
Finished: SUCCESS

(2) Jenkins 管理员密码忘记重置

1.找到用户的路径

[root@jenkins-node1 ~]# cd /var/lib/jenkins/users/
[root@jenkins-node1 users]# tree
.
├── 552408925_8628634723176281851
│   └── config.xml
├── admin_8092868597319509744
│   └── config.xml
├── jenkins_3327043579358903316     #我使用的jenkins作为管理员(如果你是admin就进admin目录)
│   └── config.xml                  #修改config.xml
└── users.xml3 directories, 4 files

2.修改jenkins用户目录下的config.xml,定位到<passwordHash>那行删除,改为如下内容-

[root@jenkins-node1 users]# vim config.xml
<passwordHash>#jbcrypt:$2a$10$slYx6.2Xyss6w9LnuiwnNOReuvkcSkaI.Y.Z2AC6Sp7hdF7hhxlsK</passwordHash>

3.新密码为bgx.com 记得重启jenkins生效

(3) Jenkins 升级迁移

描述: 在使用 Jenkins 时候显示新版本的 Jenkins (2.272) 可以下载 (变更记录),正好可以实践一哈Jenkins的升级&迁移。
PS : 如果是是在生产环境中升级建议慎重,可能会导致插件和升级版本不兼容的情况;

操作流程:

# (1) 下载更新包 
wget https://updates.jenkins.io/download/war/2.272/jenkins.war # (2) 停止 Jenkins 服务
jenkins:/usr/share/jenkins# systemctl stop jenkins && ls# jenkins.war# (3) 备份上一个版本
jenkins:/usr/share/jenkins# mv jenkins.war jenkins.war.2.263.1.bak
jenkins:/usr/share/jenkins# cp /home/weiyigeek/jenkins.war jenkins.war
jenkins:/usr/share/jenkins# ls -alh# -rw-r--r--   1 root root  67M Dec 24 02:38 jenkins.war# -rw-r--r--   1 root root  65M Dec  2 13:56 jenkins.war.2.263.1.bak# (4) 启动 Jenkins 服务
jenkins:/usr/share/jenkins# systemctl start jenkins
jenkins:/usr/share/jenkins# systemctl status jenkins# ● jenkins.service - LSB: Start Jenkins at boot time#     Loaded: loaded (/etc/init.d/jenkins; generated)#     Active: active (exited) since Thu 2020-12-24 02:38:50 UTC; 4s ago#       Docs: man:systemd-sysv-generator(8)#     Process: 448375 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)# Dec 24 02:38:48 gitlab systemd[1]: Starting LSB: Start Jenkins at boot time...# Dec 24 02:38:48 gitlab jenkins[448375]: Correct java version found# Dec 24 02:38:48 gitlab jenkins[448375]:  * Starting Jenkins Automation Server jenkins# Dec 24 02:38:48 gitlab su[448432]: (to jenkins) root on none# Dec 24 02:38:48 gitlab su[448432]: pam_unix(su-l:session): session opened for user jenkins by (uid=0)# Dec 24 02:38:49 gitlab su[448432]: pam_unix(su-l:session): session closed for user jenkins# Dec 24 02:38:50 gitlab jenkins[448375]:    ...done.# Dec 24 02:38:50 gitlab systemd[1]: Started LSB: Start Jenkins at boot time.# (5) 访问 Jenkins UI 界面验证升级版本
http://jenkins.weiyigeek.top:8080/about/


0x06 入坑&出坑

问题1.jenkins depends on daemon; however Package daemon is not installed.
问题描述: 在Ubuntu 采用 dpkg 安装 jenkins_2.263.1_all.deb 时报错提示 daemon 包未安装
问题复原:

$ sudo dpkg -i jenkins_2.263.1_all.deb
Selecting previously unselected package jenkins.
(Reading database ... 115038 files and directories currently installed.)
Preparing to unpack jenkins_2.263.1_all.deb ...
Unpacking jenkins (2.263.1) ...
dpkg: dependency problems prevent configuration of jenkins:jenkins depends on daemon; however:Package daemon is not installed.dpkg: error processing package jenkins (--install):dependency problems - leaving unconfigured
Processing triggers for systemd (245.4-4ubuntu3.2) ...
Errors were encountered while processing:jenkins

解决办法:

sudo apt install -y daemon

问题2:Jenkins 启动时显示 ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
问题复原:

$ systemctl status jenkins
Dec 23 14:02:57 gitlab systemd[1]: Starting LSB: Start Jenkins at boot time...
Dec 23 14:02:57 gitlab jenkins[356298]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
Dec 23 14:02:57 gitlab jenkins[356298]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 'type -p ja>
Dec 23 14:02:57 gitlab systemd[1]: jenkins.service: Control process exited, code=exited, status=1/FAILURE
Dec 23 14:02:57 gitlab systemd[1]: jenkins.service: Failed with result 'exit-code'.
Dec 23 14:02:57 gitlab systemd[1]: Failed to start LSB: Start Jenkins at boot time.

问题原因: 未找寻到有效的Java执行环境;
解决流程:

①.先执行echo $PATH 看看环境变量运行结果如下:
/usr/maven/maven/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/java/jdk1.8/bin
如果连这都没有的话重新安装Java。②.建立软连接:ln -s /usr/java/jdk1.8/bin/java /usr/bin/java(换成你自己的路径)
Please wait while Jenkins is getting ready to work (jenkins)
如果界面提示Jenkins正在启动,请稍后…或者提示
Please wait while Jenkins is getting ready to work…

问题3.安装Jenkins后或者安装插件时候一直在加载;
问题描述: 由于Jenkins官方插件下载地址没被墙但是网速很慢,下载时间也长;
解决方法:换清华的镜像进去之后下载插件即可 (http://updates.jenkins-ci.org/download/)
操作流程: 需要你进入jenkins的工作目录

# 打开 hudson.model.UpdateCenter.xml 把 http://updates.jenkins-ci.org/update-center.json 改成 http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
sed -i "s#updates.jenkins.io#mirrors.tuna.tsinghua.edu.cn/jenkins/updates#g" /var/lib/jenkins/hudson.model.UpdateCenter.xml# 上面的命令就是将将安装目录下的 hudson.model.UpdateCenter.xml 中改成
<?xml version='1.1' encoding='UTF-8'?>
<sites><site><id>default</id><url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url></site>
</sites># (2) 将updates文件夹下的default.json 中所有 http://updates.jenkins-ci.org/download/替换为 https://mirrors.tuna.tsinghua.edu.cn/jenkins/ PS: 也可以在后台进行设置
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json# (3) 修改完成后重启 Jenkins 即可

问题4: 未正确配置Jenkins基础URL等相关信息;
问题描述: Jenkins的根URL是空的,但是需要Jenkins的许多特性的正确操作,如电子邮件通知、PR状态更新和环境变量,如BUILD_URL。
请提供Jenkins配置中的准确值。

Jenkins root URL is empty but is required for the proper operation of many Jenkins features like email notifications, PR status update, and environment variables such as BUILD_URL.Please provide an accurate value in Jenkins configuration.

解决办法: Dashboard -> 配置 -> Jenkins Location -> Jenkins 地址 & 邮箱

问题5.无法连接仓库:Command "git ls-remote -h -- git@gitlab.weiyigeek.top:ci-cd/blog.git HEAD" returned status code 128:
问题复原:

stdout:stderr: Host key verification failed.fatal: Could not read from remote repository.
# Please make sure you have the correct access rights and the repository exists.

问题原因: 由于采用SSH协议进行代码的拉取和信息的查看,在利用公密钥首次链接时候未绑定其机器的公钥信息, 将会导致 Host key verification failed.
解决办法: 在连接的机器上先执行git -T git@gitlab.weiyigeek.top保存其主机的公钥信息;

# 例如 首次连接Gitlab时候需要进行主机于公钥绑定
ssh -T git@gitlab.com
# 无法建立主机“gitlab.com(172.65.251.78)”的真实性。
The authenticity of host 'gitlab.com (172.65.251.78)' can\'t be established.
ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw.
Are you sure you want to continue connecting (yes/no/[fingerprint])?$ cat ~/.ssh/known_hosts
gitlab.com,172.65.251.78 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAABFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QOLXBpQ6KWjbjTDTdDkoohFzgbEYI=

问题6.Jenkins 内置邮件通知发信测试 Failed to send out e-mail javax.mail.AuthenticationFailedException: 535 Error:
错误信息:

Failed to send out e-mail
javax.mail.AuthenticationFailedException: 535 Error: ÇëʹÓÃÊÚȨÂëµÇ¼¡£ÏêÇéÇë¿´: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:947)at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858)at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:762)at javax.mail.Service.connect(Service.java:364)

错误原因: 配置STMP的邮箱账号,输入的认证字符串是邮箱密码而并非生成的客户端密码, 在 腾讯企业邮箱、163邮箱都需要使用生成的客户端密码进行登录;

问题7.Jenkins 内置邮件通知发信测试 com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization user
错误信息:

Failed to send out e-mail
com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization userat com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1817)
Caused: com.sun.mail.smtp.SMTPSendFailedException: 501 mail from address must be same as authorization user
;nested exception is:com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization userat com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2374)at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1808)at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1285)at javax.mail.Transport.send0(Transport.java:231)

错误原因: 最后发现是jenkins url下面的系统管理员邮件地址没有填写或者与STMP发信邮箱不一致
解决办法: 填写系统管理员邮箱与STMP发信邮箱地址一致就可以了。

问题8.Jenkins 内置邮件通知发信测试com.sun.mail.smtp.SMTPAddressFailedException: 501 Bad address syntax

错误信息:

ERROR: Invalid Addresses
javax.mail.SendFailedException: Invalid Addresses;nested exception is:com.sun.mail.smtp.SMTPAddressFailedException: 501 Bad address syntaxat com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:2064)at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1286)at javax.mail.Transport.send0(Transport.java:231)at javax.mail.Transport.send(Transport.java:100)at hudson.tasks.MailSender.run(MailSender.java:130)at hudson.tasks.MailSender.execute(MailSender.java:105)at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.cleanUp(MavenModuleSetBuild.java:1093)at hudson.model.Run.execute(Run.java:1954)at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)at hudson.model.ResourceController.execute(ResourceController.java:97)at hudson.model.Executor.run(Executor.java:429)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 501 Bad address syntaxat com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1917)... 10 more
Finished: FAILURE

错误原因: 输入的接收邮箱地址是无效的格式;

WeiyiGeek Blog - 为了能到远方,脚下的每一步都不能少。

Tips : 本文章来源 Blog 站点或者 WeiyiGeek 公众账号 (友链交换请邮我哟):

  • 微信公众号-WeiyiGeek` # 精华文章发布地址

  • https://weiyigeek.top # 采用cloudflare CDN 国内有时访问较慢

  • https://weiyigeek.gitee.io # 国内访问快可能会有更新不及时得情况

  • 个人知乎-WeiyiGeek

Tips: 更多学习笔记文章请关注 WeiyiGeek 公众账号
【微信公众号关注(点击)】
【邮箱联系: Master#weiyigeek.top】

这篇关于5.Jenkins入门基础使用补充说明与相关问题总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1113549

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;

好题——hdu2522(小数问题:求1/n的第一个循环节)

好喜欢这题,第一次做小数问题,一开始真心没思路,然后参考了网上的一些资料。 知识点***********************************无限不循环小数即无理数,不能写作两整数之比*****************************(一开始没想到,小学没学好) 此题1/n肯定是一个有限循环小数,了解这些后就能做此题了。 按照除法的机制,用一个函数表示出来就可以了,代码如下

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu