{"id":1353,"date":"2021-08-31T16:26:20","date_gmt":"2021-08-31T08:26:20","guid":{"rendered":"https:\/\/www.siediyer.cn\/?p=1353"},"modified":"2021-08-31T16:39:05","modified_gmt":"2021-08-31T08:39:05","slug":"%e5%88%a4%e6%96%adgit%e6%98%af%e5%90%a6%e6%9c%89%e6%96%b0%e7%9a%84%e6%8f%90%e4%ba%a4","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=1353","title":{"rendered":"\u5224\u65adGit\u662f\u5426\u6709\u65b0\u7684\u63d0\u4ea4"},"content":{"rendered":"<p>\u516c\u53f8\u8981\u642d\u5efaCI\uff0c\u6709\u8fd9\u6837\u4e00\u4e2a\u9700\u6c42\uff1a\u5224\u65adGit\u662f\u5426\u6709\u65b0\u7684\u63d0\u4ea4\uff0c\u5982\u679c\u6709\u7684\u8bdd\u62c9\u53d6\u4ee3\u7801\u6784\u5efa\uff0c\u5982\u679c\u6ca1\u6709\u4e0d\u6784\u5efa\uff0cJenkins\u7684\u642d\u5efa\u8fd9\u91cc\u5c31\u4e0d\u8d58\u8ff0\u4e86\uff0c\u4e3b\u8981\u8bb2\u4e00\u4e0b\u5224\u65ad\u8fd9\u91cc\u3002<\/p>\n<p>Jenkins\u9700\u8981\u5b89\u88c5\u63d2\u4ef6Conditional BuildStep\uff0c\u5730\u5740https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Conditional+BuildStep+Plugin<\/p>\n<p>\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<p>\u6267\u884c\u811a\u672c\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#!\/bin\/bash\r\nif [ ! $GIT_PREVIOUS_SUCCESSFUL_COMMIT ];then\r\n    echo \"GIT_PREVIOUS_SUCCESSFUL_COMMIT is not exists.\"\r\n    exit 0\r\nelse\r\n    echo \"GIT_COMMIT=[$GIT_COMMIT],GIT_PREVIOUS_SUCCESSFUL_COMMIT=[$GIT_PREVIOUS_SUCCESSFUL_COMMIT]\"\r\n    if [ $GIT_PREVIOUS_SUCCESSFUL_COMMIT == $GIT_COMMIT ];then\r\n        echo \"GIT_COMMIT is equals to GIT_PREVIOUS_SUCCESSFUL_COMMIT,skip build.\"\r\n        exit -1\r\n    else\r\n        echo \"GIT_COMMIT is not equals to GIT_PREVIOUS_SUCCESSFUL_COMMIT\"\r\n        sh build_using_xctool.sh\/\/\u8fd9\u91cc\u662f\u6709\u4ee3\u7801\u66f4\u65b0\u7684\u6761\u4ef6\u4e0b\u9700\u8981\u6267\u884c\u7684\u4ee3\u7801\uff0c\u6211\u8fd9\u91cc\u662f\u8dd1\u4e00\u4e2a\u811a\u672c\r\n        exit 0\r\n    fi\r\nfi<\/pre>\n<p>\u5224\u65ad\u7684\u6761\u4ef6\u662f\u672c\u5730\u7684Git_Commit\u8ddf\u8fdc\u7aef\u8fdb\u884c\u5bf9\u6bd4\uff0c\u4e0d\u4e00\u81f4\u5c31\u4ee3\u8868\u6709\u65b0\u7684\u4ee3\u7801\u63d0\u4ea4\uff0c\u6267\u884c\u64cd\u4f5c\uff0c\u5426\u5219exit<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git branch | sed -n '\/\\* \/s\/\/\/p'\r\n\u672c\u5730\u5206\u652f\uff1a master\r\n\u8fdc\u7a0b\u8ddf\u8e2a\u5206\u652f(\u540c\u6b65) \uff1a (detached from origin\/master)\r\n\u8fdc\u7a0b\u8ddf\u8e2a\u5206\u652f(\u975e\u540c\u6b65) \uff1a (detached from origin\/feature-foo)\r\n\u6807\u7b7e\uff1a (detached from v1.2.3)\r\n\u4e00\u822c\u5206\u79bb\u5934\uff1a (detached from 285f294)\r\ngit status | head -1\r\n\u672c\u5730\u5206\u652f\uff1a # On branch master\r\n\u8fdc\u7a0b\u8ddf\u8e2a\u5206\u652f(\u540c\u6b65) \uff1a # HEAD detached at origin\/master\r\n\u8fdc\u7a0b\u8ddf\u8e2a\u5206\u652f(\u975e\u540c\u6b65) \uff1a # HEAD detached at origin\/feature-foo\r\n\u6807\u7b7e\uff1a # HEAD detached at v1.2.3\r\n\u4e00\u822c\u5206\u79bb\u5934\uff1a # HEAD detached at 285f294\r\ngit describe --all\r\n\u672c\u5730\u5206\u652f\uff1a heads\/master\r\n\u8fdc\u7a0b\u8ddf\u8e2a\u5206\u652f(\u540c\u6b65) \uff1a heads\/master ( note: \u4e0d remotes\/origin\/master )\r\n\u8fdc\u7a0b\u8ddf\u8e2a\u5206\u652f(\u975e\u540c\u6b65) \uff1a remotes\/origin\/feature-foo\r\n\u6807\u7b7e\uff1a v1.2.3\r\n\u4e00\u822c\u5206\u79bb\u5934\uff1a v1.0.6-5-g2393761\r\ncat .git\/HEAD :\r\n\u672c\u5730\u5206\u652f\uff1a ref: refs\/heads\/master\r\n\u6240\u6709\u5176\u5b83\u7528\u4f8b\uff1a SHA\u5bf9\u5e94\u7684commit\r\ngit rev-parse --abbrev-ref HEAD\r\n\u672c\u5730\u5206\u652f\uff1a master\r\n\u6240\u6709\u5176\u5b83\u7528\u4f8b\uff1a HEAD\r\ngit symbolic-ref --short HEAD\r\n\u672c\u5730\u5206\u652f\uff1a master\r\n\u6240\u6709\u5176\u5b83\u7528\u4f8b\uff1a fatal: ref HEAD is not a symbolic ref<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u516c\u53f8\u8981\u642d\u5efaCI\uff0c\u6709\u8fd9\u6837\u4e00\u4e2a\u9700\u6c42\uff1a\u5224\u65adGit\u662f\u5426\u6709\u65b0\u7684\u63d0\u4ea4\uff0c\u5982\u679c\u6709\u7684\u8bdd\u62c9\u53d6\u4ee3\u7801\u6784\u5efa\uff0c\u5982\u679c\u6ca1\u6709\u4e0d\u6784\u5efa\uff0cJenkin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1353","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1353"}],"version-history":[{"count":2,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1353\/revisions"}],"predecessor-version":[{"id":1355,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1353\/revisions\/1355"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}